You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2007/04/27 19:38:18 UTC

svn commit: r533175 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java

Author: kahatlen
Date: Fri Apr 27 10:38:17 2007
New Revision: 533175

URL: http://svn.apache.org/viewvc?view=rev&rev=533175
Log:
DERBY-2595: JUnit tests use getExportedKeys with table name null

Rewrote invalid usage of DatabaseMetaData.getExportedKeys() in
JDBC.dropSchema().

Contributed by Jørgen Løland.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java?view=diff&rev=533175&r1=533174&r2=533175
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java Fri Apr 27 10:38:17 2007
@@ -221,26 +221,32 @@
         // foreign key constraints leading to a dependency loop.
         // Drop any constraints that remain and then drop the tables.
         // If there are no tables then this should be a quick no-op.
-        rs = dmd.getExportedKeys((String) null, schema, (String) null);
-        while (rs.next())
-        {
-            short keyPosition = rs.getShort("KEY_SEQ");
-            if (keyPosition != 1)
-                continue;
-            String fkName = rs.getString("FK_NAME");
-            // No name, probably can't happen but couldn't drop it anyway.
-            if (fkName == null)
-                continue;
-            String fkSchema = rs.getString("FKTABLE_SCHEM");
-            String fkTable = rs.getString("FKTABLE_NAME");
-            
-            String ddl = "ALTER TABLE " +
-                JDBC.escape(fkSchema, fkTable) +
-                " DROP FOREIGN KEY " +
-                JDBC.escape(fkName);
-            s.executeUpdate(ddl);
+        ResultSet table_rs = dmd.getTables((String) null, schema, (String) null,
+                new String[] {"TABLE"});
+
+        while (table_rs.next()) {
+            String tablename = table_rs.getString("TABLE_NAME");
+            rs = dmd.getExportedKeys((String) null, schema, tablename);
+            while (rs.next()) {
+                short keyPosition = rs.getShort("KEY_SEQ");
+                if (keyPosition != 1)
+                    continue;
+                String fkName = rs.getString("FK_NAME");
+                // No name, probably can't happen but couldn't drop it anyway.
+                if (fkName == null)
+                    continue;
+                String fkSchema = rs.getString("FKTABLE_SCHEM");
+                String fkTable = rs.getString("FKTABLE_NAME");
+
+                String ddl = "ALTER TABLE " +
+                    JDBC.escape(fkSchema, fkTable) +
+                    " DROP FOREIGN KEY " +
+                    JDBC.escape(fkName);
+                s.executeUpdate(ddl);
+            }
+            rs.close();
         }
-        rs.close();
+        table_rs.close();
         conn.commit();
                 
         // Tables (again)