db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r885595 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Mon, 30 Nov 2009 22:22:16 GMT
Author: dag
Date: Mon Nov 30 22:22:15 2009
New Revision: 885595

URL: http://svn.apache.org/viewvc?rev=885595&view=rev
Log:
DERBY-4426 With generated columns, INSERT with DEFAULT inside a VALUES clause inside a UNION
fails

Patch derby-4426c, which fixes this issue. We ensure that DEFAULT is
only used in a top level VALUES clause, conformant with the standard. 


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/RowResultSetNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SelectNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SetOperatorNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SingleChildResultSetNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableOperatorNode.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ColumnDefaultsTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsHelper.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java?rev=885595&r1=885594&r2=885595&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InsertNode.java Mon
Nov 30 22:22:15 2009
@@ -295,8 +295,18 @@
 				" on return from RS.bindExpressions()");
 		}
 
-		/* Replace any DEFAULTs with the associated tree */
-		resultSet.replaceDefaults(targetTableDescriptor, targetColumnList);
+        /* Replace any DEFAULTs with the associated tree, or flag DEFAULTs if
+         * not allowed (inside top level set operator nodes). Subqueries are
+         * checked for illegal DEFAULTs elsewhere.
+         */
+        boolean isTableConstructor =
+            (resultSet instanceof UnionNode &&
+             ((UnionNode)resultSet).tableConstructor()) ||
+            resultSet instanceof RowResultSetNode;
+
+        resultSet.replaceOrForbidDefaults(targetTableDescriptor,
+                                          targetColumnList,
+                                          isTableConstructor);
 
 		/* Bind the expressions now that the result columns are bound 
 		 * NOTE: This will be the 2nd time for those underlying ResultSets

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java?rev=885595&r1=885594&r2=885595&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
Mon Nov 30 22:22:15 2009
@@ -3864,14 +3864,18 @@
 	}
 
 	/**
-	 * Replace any DEFAULTs with the associated tree for the default.
+	 * Replace any DEFAULTs with the associated tree for the default if
+	 * allowed, or flag.
 	 *
 	 * @param ttd	The TableDescriptor for the target table.
 	 * @param tcl	The RCL for the target table.
+     * @param allowDefaults true if allowed
 	 *
 	 * @exception StandardException		Thrown on error
 	 */
-	void replaceDefaults(TableDescriptor ttd, ResultColumnList tcl) 
+	void replaceOrForbidDefaults(TableDescriptor ttd,
+                                 ResultColumnList tcl,
+                                 boolean allowDefaults)
 		throws StandardException
 	{
 		int size = size();
@@ -3882,6 +3886,11 @@
 
 			if (rc.isDefaultColumn())
 			{
+                if (!allowDefaults) {
+                    throw StandardException.newException(
+                        SQLState.LANG_INVALID_USE_OF_DEFAULT);
+                }
+
 				//				DefaultNode defaultNode = (DefaultNode) rc.getExpression();
 				// Get ColumnDescriptor by name or by position?
 				ColumnDescriptor cd;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java?rev=885595&r1=885594&r2=885595&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java Mon
Nov 30 22:22:15 2009
@@ -1763,19 +1763,28 @@
 		return false;
 	}
 
-	/**
-	 * Replace any DEFAULTs with the associated tree for the default.
-	 *
-	 * @param ttd	The TableDescriptor for the target table.
-	 * @param tcl	The RCL for the target table.
-	 *
-	 * @exception StandardException		Thrown on error
-	 */
-	void replaceDefaults(TableDescriptor ttd, ResultColumnList tcl) 
-		throws StandardException
-	{
-		// Only subclasses with something to do override this.
-	}
+    /**
+     * Replace any DEFAULTs with the associated tree for the default if
+     * allowed, or flag (when inside top level set operator nodes). Subqueries
+     * are checked for illegal DEFAULTs elsewhere.
+     *
+     * @param ttd   The TableDescriptor for the target table.
+     * @param tcl   The RCL for the target table.
+     * @param allowDefaults true if allowed
+     *
+     * @exception StandardException         Thrown on error
+     */
+    void replaceOrForbidDefaults(TableDescriptor ttd,
+                                 ResultColumnList tcl,
+                                 boolean allowDefaults)
+        throws StandardException
+    {
+        if (SanityManager.DEBUG) {
+            SanityManager.THROWASSERT(
+                "replaceOrForbidDefaults() not expected to be called for " +
+                this.getClass().getName());
+        }
+    }
 
 	/**
 	 * Is it possible to do a distinct scan on this ResultSet tree.

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/RowResultSetNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/RowResultSetNode.java?rev=885595&r1=885594&r2=885595&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/RowResultSetNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/RowResultSetNode.java
Mon Nov 30 22:22:15 2009
@@ -853,17 +853,14 @@
 	}
 
 	/**
-	 * Replace any DEFAULTs with the associated tree for the default.
-	 *
-	 * @param ttd	The TableDescriptor for the target table.
-	 * @param tcl	The RCL for the target table.
-	 *
-	 * @exception StandardException		Thrown on error
+     * {@inheritDoc}
 	 */
-	void replaceDefaults(TableDescriptor ttd, ResultColumnList tcl) 
+	void replaceOrForbidDefaults(TableDescriptor ttd,
+                                 ResultColumnList tcl,
+                                 boolean allowDefaults)
 		throws StandardException
 	{
-		resultColumns.replaceDefaults(ttd, tcl);
+		resultColumns.replaceOrForbidDefaults(ttd, tcl, allowDefaults);
 	}
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SelectNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SelectNode.java?rev=885595&r1=885594&r2=885595&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SelectNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SelectNode.java Mon
Nov 30 22:22:15 2009
@@ -2423,4 +2423,16 @@
 				clauseName);
 		}
 	}
+
+    /**
+     * {@inheritDoc}
+     *
+     * A no-op for SelectNode.
+     */
+    void replaceOrForbidDefaults(TableDescriptor ttd,
+                                 ResultColumnList tcl,
+                                 boolean allowDefaults)
+        throws StandardException
+    {
+    }
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SetOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SetOperatorNode.java?rev=885595&r1=885594&r2=885595&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SetOperatorNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SetOperatorNode.java
Mon Nov 30 22:22:15 2009
@@ -686,7 +686,20 @@
 		}			
 	}
 
-	/**
+    /**
+     * {@inheritDoc}
+     */
+    void replaceOrForbidDefaults(TableDescriptor ttd,
+                                 ResultColumnList tcl,
+                                 boolean allowDefaults)
+        throws StandardException
+    {
+        leftResultSet.replaceOrForbidDefaults(ttd, tcl, allowDefaults);
+        rightResultSet.replaceOrForbidDefaults(ttd, tcl, allowDefaults);
+    }
+
+
+    /**
 	 * Get the parameter types from the given RowResultSetNode into the
 	 * given array of types.  If an array position is already filled in,
 	 * don't clobber it.

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SingleChildResultSetNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SingleChildResultSetNode.java?rev=885595&r1=885594&r2=885595&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SingleChildResultSetNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SingleChildResultSetNode.java
Mon Nov 30 22:22:15 2009
@@ -555,20 +555,6 @@
 	}
 
 	/**
-	 * Replace any DEFAULTs with the associated tree for the default.
-	 *
-	 * @param ttd	The TableDescriptor for the target table.
-	 * @param tcl	The RCL for the target table.
-	 *
-	 * @exception StandardException		Thrown on error
-	 */
-	void replaceDefaults(TableDescriptor ttd, ResultColumnList tcl) 
-		throws StandardException
-	{
-		childResult.replaceDefaults(ttd, tcl);
-	}
-
-	/**
 	 * @see ResultSetNode#adjustForSortElimination
 	 */
 	void adjustForSortElimination()

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableOperatorNode.java?rev=885595&r1=885594&r2=885595&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableOperatorNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableOperatorNode.java
Mon Nov 30 22:22:15 2009
@@ -929,21 +929,6 @@
 	}
 
 	/**
-	 * Replace any DEFAULTs with the associated tree for the default.
-	 *
-	 * @param ttd	The TableDescriptor for the target table.
-	 * @param tcl	The RCL for the target table.
-	 *
-	 * @exception StandardException		Thrown on error
-	 */
-	void replaceDefaults(TableDescriptor ttd, ResultColumnList tcl) 
-		throws StandardException
-	{
-		leftResultSet.replaceDefaults(ttd, tcl);
-		rightResultSet.replaceDefaults(ttd, tcl);
-	}
-
-	/**
 	 * @see ResultSetNode#adjustForSortElimination
 	 */
 	void adjustForSortElimination()

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ColumnDefaultsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ColumnDefaultsTest.java?rev=885595&r1=885594&r2=885595&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ColumnDefaultsTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ColumnDefaultsTest.java
Mon Nov 30 22:22:15 2009
@@ -144,7 +144,19 @@
         
         assertStatementError("42802", st,
             " insert into neg values (default, 1)");
-        
+
+
+        // DERBY-4426
+        assertStatementError("42Y85", st,
+            " insert into neg values (default) union values (default)");
+
+        assertStatementError("42Y85", st,
+            " insert into neg values (default) except values (default)");
+
+        // Make sure sub-queries are inspected for illegal DEFAULT also.
+        assertStatementError("42Y85", st,
+            " insert into neg select * from (values default) t");
+
         st.executeUpdate( " drop table neg");
         
         st.executeUpdate( "drop function asdf");
@@ -402,7 +414,21 @@
         };
         
         JDBC.assertFullResultSet(rs, expRS, true);
-        
+
+        // DERBY-4426: make sure we don't forbid inside a multi-value table
+        // constructor since this is represented as a UnionNode
+        st.executeUpdate( "delete from t7");
+        st.executeUpdate( "insert into t7 values 1, default");
+        rs = st.executeQuery( " select * from t7");
+
+        expRS = new String [][]
+        {
+            {"1"},
+            {"10"}
+        };
+
+        JDBC.assertFullResultSet(rs, expRS, true);
+
         st.executeUpdate( " drop table t1");
         
         st.executeUpdate( " drop table t7");

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsHelper.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsHelper.java?rev=885595&r1=885594&r2=885595&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsHelper.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsHelper.java
Mon Nov 30 22:22:15 2009
@@ -87,7 +87,8 @@
     protected static  final   String  CASCADED_COLUMN_DROP_WARNING = "01009";
     protected static  final   String  CONSTRAINT_DROPPED_WARNING = "01500";
     protected static  final   String  TRIGGER_DROPPED_WARNING = "01502";
-    
+    protected static  final   String  LANG_INVALID_USE_OF_DEFAULT = "42Y85";
+
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // STATE

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java?rev=885595&r1=885594&r2=885595&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
Mon Nov 30 22:22:15 2009
@@ -233,6 +233,43 @@
         rollback();
     }
 
+
+    /**
+     * Test for DERBY-4426
+     */
+    public void testDerby_4426() throws SQLException {
+
+        Statement s = createStatement();
+        ResultSet rs = null;
+        setAutoCommit(false);
+
+        s.execute("create table t(a int, b generated always as (-a))");
+        s.execute("insert into t(b,a) values (default,1)");
+
+        // Wrong use of default
+        expectCompilationError
+            (
+             LANG_INVALID_USE_OF_DEFAULT,
+             "insert into t(b,a) values (default,3) intersect " +
+             "                   values (default,3)"
+             );
+
+        expectCompilationError
+            (
+             LANG_INVALID_USE_OF_DEFAULT,
+             "insert into t(a,b) values (3,default) except values (3,default)"
+             );
+
+        expectCompilationError
+            (
+             LANG_INVALID_USE_OF_DEFAULT,
+             "insert into t values (3,default) union values (3,default)"
+             );
+
+
+        rollback();
+    }
+
     /**
      * <p>
      * Test that the stored system procedures and functions are non-deterministic. If you
want



Mime
View raw message