db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r641398 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_4.java
Date Wed, 26 Mar 2008 16:52:35 GMT
Author: kmarsden
Date: Wed Mar 26 09:52:27 2008
New Revision: 641398

URL: http://svn.apache.org/viewvc?rev=641398&view=rev
Log:
DERBY-3523 sql states (X0Y63, X0Y63, X0Y63.S) related to nulls in unique constraints are associated
with wrong message texts

Add upgrade test to verify messages are the same when created with 10.3 and 
with soft upgrade.

Contributed by Anurag Shekhar (anurag dot shekhar at sun dot com)
 

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_4.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_4.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_4.java?rev=641398&r1=641397&r2=641398&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_4.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_4.java
Wed Mar 26 09:52:27 2008
@@ -627,4 +627,94 @@
         }
         s.close();
     }
+    
+    /**
+     * Verifies error messages priviously generated.
+     */
+    private void verifyError() throws SQLException {
+        Statement stmt = createStatement();
+        PreparedStatement ps = prepareStatement("select text " +
+                                    "from errormessage where state = ?");
+        try {
+            stmt.execute("alter table t1 alter column i null");
+            fail ("expected error while setting primary key " +
+                    "column to nullable");
+        } catch (SQLException e) {
+            assertSQLState("expected state 42Z20", "42Z20", e);
+            ps.setString(1, e.getSQLState());
+            ResultSet rs = ps.executeQuery();
+            rs.next();
+            assertEquals("error message mismatch", rs.getString(1),
+                                    e.getMessage());
+            rs.close();
+        }
+        try {
+            stmt.execute("alter table t1 add constraint  uidx " +
+                    "unique(j)");
+            fail ("expected error while creating unique constraint " +
+                    "over nullable column");
+
+        } catch (SQLException e) {
+            assertSQLState("expected state 42831", "42831", e);
+            ps.setString(1, e.getSQLState());
+            ResultSet rs = ps.executeQuery();
+            rs.next();
+            assertEquals("error message mismatch", rs.getString(1),
+                                    e.getMessage());
+            rs.close();
+        }
+        stmt.close();
+        ps.close();
+    }
+    
+    /**
+     * Generates error messages and stores in a table.
+     */
+    private void prepareTable() throws SQLException {
+        Statement stmt = createStatement();
+        stmt.executeUpdate("create table errormessage (state varchar (6), " +
+                                            "text varchar (200))");
+        PreparedStatement ps = prepareStatement("insert into errormessage " +
+                    "(state, text) values (?, ?)");
+        stmt.executeUpdate("create table t1 (i integer primary key, " +
+                                                            "j integer)");
+        try {
+            stmt.execute("alter table t1 alter column i null");
+            fail ("expected error while setting primary key " +
+                    "column to nullable");
+        } catch (SQLException e) {
+            assertSQLState("expected state 42Z20", "42Z20", e);
+            ps.setString(1, e.getSQLState());
+            ps.setString(2, e.getMessage());
+            ps.executeUpdate();
+        }
+        try {
+            stmt.execute("alter table t1 add constraint  uidx " +
+                    "unique(j)");
+            fail ("expected error while creating unique constraint " +
+                    "over nullable column");
+        } catch (SQLException e) {
+            assertSQLState("expected state 42831", "42831", e);
+            ps.setString(1, e.getSQLState());
+            ps.setString(2, e.getMessage());
+            ps.executeUpdate();
+        }
+        stmt.close();
+        ps.close();
+    }
+    
+    /**
+     * check if error message generated during soft upgrade is 
+     * same as privious version.
+     */
+    public void testErrorMessage () throws Exception {
+        switch (getPhase()) {
+            case PH_CREATE:
+                prepareTable();
+                break;
+            case PH_SOFT_UPGRADE:
+                verifyError();
+                break;
+        }
+    }
 }



Mime
View raw message