diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java b/src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java index e819d4b9262..d8327f1544c 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java @@ -15,7 +15,7 @@ import org.postgresql.util.PSQLException; /* * This class provides information about the database as a whole. * - * $Id: DatabaseMetaData.java,v 1.52 2002/04/16 13:28:44 davec Exp $ + * $Id: DatabaseMetaData.java,v 1.53 2002/06/05 19:12:01 davec Exp $ * *
Many of the methods here return lists of information in ResultSets. You
* can use the normal ResultSet methods such as getString and getInt to
@@ -760,8 +760,10 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
*/
public boolean supportsANSI92EntryLevelSQL() throws SQLException
{
- Driver.debug("supportsANSI92EntryLevelSQL false ");
- return false;
+ boolean schemas = connection.haveMinimumServerVersion("7.3");
+ Driver.debug("supportsANSI92EntryLevelSQL " + schemas);
+ return schemas;
+
}
/*
@@ -941,8 +943,10 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
*/
public boolean supportsSchemasInTableDefinitions() throws SQLException
{
- Driver.debug("supportsSchemasInTableDefinitions false");
- return false;
+ boolean schemas = connection.haveMinimumServerVersion("7.3");
+
+ Driver.debug("supportsSchemasInTableDefinitions " + schemas);
+ return schemas;
}
/*
@@ -2410,6 +2414,71 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
" ORDER BY table_name, pk_name, key_seq"
);
}
+/*
+ SELECT
+ c.relname as primary,
+ c2.relname as foreign,
+ t.tgconstrname,
+ ic.relname as fkeyname,
+ af.attnum as fkeyseq,
+ ipc.relname as pkeyname,
+ ap.attnum as pkeyseq,
+ t.tgdeferrable,
+ t.tginitdeferred,
+ t.tgnargs,t.tgargs,
+ p1.proname as updaterule,
+ p2.proname as deleterule
+FROM
+ pg_trigger t,
+ pg_trigger t1,
+ pg_class c,
+ pg_class c2,
+ pg_class ic,
+ pg_class ipc,
+ pg_proc p1,
+ pg_proc p2,
+ pg_index if,
+ pg_index ip,
+ pg_attribute af,
+ pg_attribute ap
+WHERE
+ (t.tgrelid=c.oid
+ AND t.tgisconstraint
+ AND t.tgconstrrelid=c2.oid
+ AND t.tgfoid=p1.oid
+ and p1.proname like '%%upd')
+
+ and
+ (t1.tgrelid=c.oid
+ and t1.tgisconstraint
+ and t1.tgconstrrelid=c2.oid
+ AND t1.tgfoid=p2.oid
+ and p2.proname like '%%del')
+
+ AND c2.relname='users'
+
+ AND
+ (if.indrelid=c.oid
+ AND if.indexrelid=ic.oid
+ and ic.oid=af.attrelid
+ AND if.indisprimary)
+
+ and
+ (ip.indrelid=c2.oid
+ and ip.indexrelid=ipc.oid
+ and ipc.oid=ap.attrelid
+ and ip.indisprimary)
+
+*/
+/**
+ *
+ * @param catalog
+ * @param schema
+ * @param primaryTable if provided will get the keys exported by this table
+ * @param foreignTable if provided will get the keys imported by this table
+ * @return ResultSet
+ * @throws SQLException
+ */
private java.sql.ResultSet getImportedExportedKeys(String catalog, String schema, String primaryTable, String foreignTable) throws SQLException
{
@@ -2430,120 +2499,203 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
f[12] = new Field(connection, "PK_NAME", iVarcharOid, 32);
f[13] = new Field(connection, "DEFERRABILITY", iInt2Oid, 2);
- java.sql.ResultSet rs = connection.ExecSQL("SELECT c.relname,c2.relname,"
- + "t.tgconstrname,ic.relname,"
- + "t.tgdeferrable,t.tginitdeferred,"
- + "t.tgnargs,t.tgargs,p.proname "
- + "FROM pg_trigger t,pg_class c,pg_class c2,"
- + "pg_class ic,pg_proc p, pg_index i "
- + "WHERE t.tgrelid=c.oid AND t.tgconstrrelid=c2.oid "
- + "AND t.tgfoid=p.oid AND tgisconstraint "
- + ((primaryTable != null) ? "AND c.relname='" + primaryTable + "' " : "")
- + ((foreignTable != null) ? "AND c2.relname='" + foreignTable + "' " : "")
- + "AND i.indrelid=c.oid "
- + "AND i.indexrelid=ic.oid AND i.indisprimary "
- + "ORDER BY c.relname,c2.relname"
- );
+ java.sql.ResultSet rs = connection.ExecSQL(
+ "SELECT "
+ + "c.relname as prelname, "
+ + "c2.relname as frelname, "
+ + "t.tgconstrname, "
+ + "a.attnum as keyseq, "
+ + "ic.relname as fkeyname, "
+ + "t.tgdeferrable, "
+ + "t.tginitdeferred, "
+ + "t.tgnargs,t.tgargs, "
+ + "p1.proname as updaterule, "
+ + "p2.proname as deleterule "
+ + "FROM "
+ + "pg_trigger t, "
+ + "pg_trigger t1, "
+ + "pg_class c, "
+ + "pg_class c2, "
+ + "pg_class ic, "
+ + "pg_proc p1, "
+ + "pg_proc p2, "
+ + "pg_index i, "
+ + "pg_attribute a "
+ + "WHERE "
+ // isolate the update rule
+ + "(t.tgrelid=c.oid "
+ + "AND t.tgisconstraint "
+ + "AND t.tgconstrrelid=c2.oid "
+ + "AND t.tgfoid=p1.oid "
+ + "and p1.proname like '%%upd') "
+
+ + "and "
+ // isolate the delete rule
+ + "(t1.tgrelid=c.oid "
+ + "and t1.tgisconstraint "
+ + "and t1.tgconstrrelid=c2.oid "
+ + "AND t1.tgfoid=p2.oid "
+ + "and p2.proname like '%%del') "
+
+ // if we are looking for exported keys then primary table will be used
+ + ((primaryTable != null) ? "AND c.relname='" + primaryTable + "' " : "")
+
+ // if we are looking for imported keys then the foreign table will be used
+ + ((foreignTable != null) ? "AND c2.relname='" + foreignTable + "' " : "")
+ + "AND i.indrelid=c.oid "
+ + "AND i.indexrelid=ic.oid "
+ + "AND ic.oid=a.attrelid "
+ + "AND i.indisprimary "
+ + "ORDER BY "
+
+ // orderby is as follows getExported, orders by FKTABLE,
+ // getImported orders by PKTABLE
+ // getCrossReference orders by FKTABLE, so this should work for both,
+ // since when getting crossreference, primaryTable will be defined
+
+ + (primaryTable != null ? "frelname" : "prelname") + ",keyseq");
+
+// returns the following columns
+// and some example data with a table defined as follows
+
+// create table people ( id int primary key);
+// create table policy ( id int primary key);
+// create table users ( id int primary key, people_id int references people(id), policy_id int references policy(id))
+
+// prelname | frelname | tgconstrname | keyseq | fkeyName | tgdeferrable | tginitdeferred
+// 1 | 2 | 3 | 4 | 5 | 6 | 7
+
+// people | users |