db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r641911 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_4.java
Date Thu, 27 Mar 2008 17:27:51 GMT
Author: kmarsden
Date: Thu Mar 27 10:27:44 2008
New Revision: 641911

URL: http://svn.apache.org/viewvc?rev=641911&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 tests.  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=641911&r1=641910&r2=641911&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
Thu Mar 27 10:27:44 2008
@@ -627,4 +627,98 @@
         }
         s.close();
     }
+    
+    /**
+     * Verifies error messages priviously generated.
+     */
+    private void verifyError() throws SQLException {
+        Statement stmt = createStatement();
+        PreparedStatement ps = prepareStatement("select text " +
+                                    "from errormessage where state = ?");
+        if (oldAtLeast(10,2)) {
+            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 not null primary key, " +
+                                                            "j integer)");
+        if (oldAtLeast(10,2)) {
+            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