db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r948799 - in /db/derby/code/branches/10.5: ./ java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java java/testing/org/apache/derbyTesting/functionTests/tests/lang/InsertTest.java
Date Thu, 27 May 2010 12:18:23 GMT
Author: kahatlen
Date: Thu May 27 12:18:23 2010
New Revision: 948799

URL: http://svn.apache.org/viewvc?rev=948799&view=rev
Log:
DERBY-4671: Embedded driver does not work with jbossCache

Merged fix from trunk (revision 948045).

Modified:
    db/derby/code/branches/10.5/   (props changed)
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/InsertTest.java

Propchange: db/derby/code/branches/10.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu May 27 12:18:23 2010
@@ -1 +1 @@
-/db/derby/code/trunk:769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,792434,793089,793588,794106,794303,794955,795166,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,829022,832379,833430,835286,881074,881444,882732,884163,887246,892912,897161,901165,901648,901760,903108,911315,915733,916075,916897,918359,921028,927430,946794
+/db/derby/code/trunk:769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,792434,793089,793588,794106,794303,794955,795166,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,829022,832379,833430,835286,881074,881444,882732,884163,887246,892912,897161,901165,901648,901760,903108,911315,915733,916075,916897,918359,921028,927430,946794,948045

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java?rev=948799&r1=948798&r2=948799&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java
(original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java
Thu May 27 12:18:23 2010
@@ -304,12 +304,8 @@ public abstract class ResultSetNode exte
 	}
 
 	/**
-	 * Set the type of each parameter in the result column list if this node
-	 * represents a table constructor (aka VALUES clause). Table constructors
-	 * are represented either by a {@code RowResultSetNode} or by a
-	 * {@code UnionNode} with multiple {@code RowResultSetNode} children and
-	 * whose {@code tableConstructor()} method returns {@code true}. For all
-	 * other nodes, this method should be a no-op.
+	 * Set the type of each parameter in the result column list for this
+	 * table constructor.
 	 *
 	 * @param typeColumns	The ResultColumnList containing the desired result
 	 *						types.
@@ -319,9 +315,17 @@ public abstract class ResultSetNode exte
 	void setTableConstructorTypes(ResultColumnList typeColumns)
 			throws StandardException
 	{
-		// Nothing to be done unless this node represents a VALUES clause, in
-		// which case the overrides in RowResultSetNode or UnionNode will do
-		// the necessary work.
+        // VALUES clause needs special handling that's taken care of in a
+        // sub-class. For all other nodes, just go through the result columns
+        // and set the type for dynamic parameters.
+        for (int i = 0; i < resultColumns.size(); i++) {
+            ResultColumn rc = (ResultColumn) resultColumns.elementAt(i);
+            ValueNode re = rc.getExpression();
+            if (re != null && re.requiresTypeFromContext()) {
+                ResultColumn typeCol = (ResultColumn) typeColumns.elementAt(i);
+                re.setType(typeCol.getTypeServices());
+            }
+        }
 	}
 
 	/**

Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/InsertTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/InsertTest.java?rev=948799&r1=948798&r2=948799&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/InsertTest.java
(original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/InsertTest.java
Thu May 27 12:18:23 2010
@@ -34,6 +34,8 @@ import org.apache.derbyTesting.junit.Tes
  */
 public class InsertTest extends BaseJDBCTestCase {
 
+    private static final String PARAMETER_IN_SELECT_LIST = "42X34";
+
     public InsertTest(String name) {
         super(name);
     }
@@ -134,4 +136,55 @@ public class InsertTest extends BaseJDBC
                 "1");
         s.execute("delete from t3");
     }
+
+    /**
+     * Regression test for DERBY-4671. Verify that dynamic parameters can be
+     * used in the select list in an INSERT INTO ... SELECT FROM statement.
+     * This used to work, but the fix for DERBY-4420 made it throw a
+     * NullPointerException.
+     */
+    public void testInsertFromSelectWithParameters() throws SQLException {
+        Statement s = createStatement();
+        s.execute("create table derby4671(x int)");
+        s.execute("insert into derby4671 values (1), (2)");
+
+        // This call failed with a NullPointerException
+        PreparedStatement ins1 = prepareStatement(
+                "insert into derby4671 select ? from derby4671");
+
+        ins1.setInt(1, 7);
+        assertUpdateCount(ins1, 2);
+
+        JDBC.assertFullResultSet(
+                s.executeQuery("select * from derby4671 order by x"),
+                new String[][] {{"1"}, {"2"}, {"7"}, {"7"}});
+
+        // Also verify that it works when the ? is in an expression
+        PreparedStatement ins2 = prepareStatement(
+                "insert into derby4671 select (x+?)*10 from derby4671");
+
+        ins2.setInt(1, 77);
+        assertUpdateCount(ins2, 4);
+
+        JDBC.assertFullResultSet(
+                s.executeQuery("select * from derby4671 order by x"),
+                new String[][] {
+                    {"1"}, {"2"}, {"7"}, {"7"},
+                    {"780"}, {"790"}, {"840"}, {"840"}});
+
+        // We only accept ? in the top level select list, so these should
+        // still fail
+        assertCompileError(
+                PARAMETER_IN_SELECT_LIST,
+                "insert into derby4671 select ? from derby4671 "
+                + "union select ? from derby4671");
+        assertCompileError(
+                PARAMETER_IN_SELECT_LIST,
+                "insert into derby4671 select ? from derby4671 "
+                + "except select ? from derby4671");
+        assertCompileError(
+                PARAMETER_IN_SELECT_LIST,
+                "insert into derby4671 select ? from derby4671 "
+                + "intersect select ? from derby4671");
+    }
 }



Mime
View raw message