db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r615458 - in /db/derby/code/branches/10.3/java: engine/org/apache/derby/impl/sql/compile/ResultColumn.java testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java
Date Sat, 26 Jan 2008 16:06:25 GMT
Author: dyre
Date: Sat Jan 26 08:06:23 2008
New Revision: 615458

URL: http://svn.apache.org/viewvc?rev=615458&view=rev
Log:
DERBY-3343: Subsequent calls to PreparedStatement cause SQLIntegrityConstraintViolationException
on column that is "Generated always"

Modifies the logic in ResultColumn.getOrderableVariantType() so that it behaves
correctly even when a default column is explicitly mentioned in an insert statement.

Merged with svn merge -r 615202:615203 ../derby-commit

Simple merge with no conflicts; no additional changes were necessary.

Modified:
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ResultColumn.java
    db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ResultColumn.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ResultColumn.java?rev=615458&r1=615457&r2=615458&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ResultColumn.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ResultColumn.java
Sat Jan 26 08:06:23 2008
@@ -1492,14 +1492,16 @@
 		** return VARIANT.  Otherwise, we return
 		** CONSTANT. For result columns that are 
 		** generating autoincrement values, the result
-		** is variant-- note that there is no expression
-		** associated with an autoincrement column in 
-		** an insert statement.
+		** is variant.
 		*/
-		int expType = ((expression != null) ?
-					   expression.getOrderableVariantType() : 
-					   ((isAutoincrementGenerated()) ? 
-						Qualifier.VARIANT : Qualifier.CONSTANT));
+        int expType;
+        if (isAutoincrementGenerated()) {
+            expType = Qualifier.VARIANT;
+        } else if (expression != null) {
+            expType = expression.getOrderableVariantType();
+        } else {
+            expType = Qualifier.CONSTANT;
+        }
 
 		switch (expType)
 		{

Modified: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java?rev=615458&r1=615457&r2=615458&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java
(original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java
Sat Jan 26 08:06:23 2008
@@ -21,9 +21,6 @@
 
 package org.apache.derbyTesting.functionTests.tests.lang;
 
-import java.util.HashMap;
-import java.util.Iterator;
-
 import java.sql.Connection;
 import java.sql.Statement;
 import java.sql.PreparedStatement;
@@ -2049,5 +2046,54 @@
             assertResultSet("R?="+i+" ?="+(i+1), empty, rs);
         }
         tst.close();
+    }
+
+
+    // Regression tests for DERBY-3343 (regression from the fix for DERBY-827)
+    /**
+     * Private helper method. Runs the same test for different
+     * generated identity columns.
+     * @param dataType SMALLINT, INT, or BIGINT
+     * @param generatedType BY DEFAULT or ALWAYS
+     * @throws Exception all errors passed on to JUnit
+     */
+    private void testGeneratedIdentity(String dataType, String generateType) 
+        throws Exception {
+        Statement s = createStatement();
+        s.execute("CREATE TABLE T(GI "+dataType+" PRIMARY KEY GENERATED "+
+                  generateType+
+                  " AS IDENTITY (START WITH 5, INCREMENT BY 10), "+
+                  "L VARCHAR(8))");
+        PreparedStatement implicit = 
+            prepareStatement("INSERT INTO T(L) VALUES('implicit')"); 
+        implicit.executeUpdate();
+        implicit.executeUpdate();
+        implicit.executeUpdate();
+        
+        PreparedStatement explicit = 
+            prepareStatement("INSERT INTO T(GI, L) "+
+                             "VALUES(DEFAULT, 'explicit')"); 
+        explicit.executeUpdate();
+        explicit.executeUpdate();
+        explicit.executeUpdate();
+    } 
+    public void testIntGeneratedByDefaultAsIdentity() throws Exception {
+        testGeneratedIdentity("INT","BY DEFAULT");
+    }
+    public void testSmallintGeneratedByDefaultAsIdentity() throws Exception {
+        testGeneratedIdentity("SMALLINT","BY DEFAULT");
+    }
+    public void testBigintGeneratedByDefaultAsIdentity() throws Exception {
+        testGeneratedIdentity("BIGINT","BY DEFAULT");
+    }
+
+    public void testIntGeneratedAlwaysAsIdentity() throws Exception {
+        testGeneratedIdentity("INT","ALWAYS");
+    }
+    public void testSmallintGeneratedAlwaysAsIdentity() throws Exception {
+        testGeneratedIdentity("SMALLINT","ALWAYS");
+    }
+    public void testBigintGeneratedAlwaysAsIdentity() throws Exception {
+        testGeneratedIdentity("BIGINT","ALWAYS");
     }
 }



Mime
View raw message