db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1566649 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ engine/org/apache/derby/loc/ shared/org/apache/derby/shared/common/reference/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Mon, 10 Feb 2014 15:10:32 GMT
Author: rhillegas
Date: Mon Feb 10 15:10:31 2014
New Revision: 1566649

URL: http://svn.apache.org/r1566649
Log:
DERBY-3155: Forbid derived column lists in MERGE statements; commit derby-3155-23-aa-forbidDerivedColumnLists.diff.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MergeNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MergeNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MergeNode.java?rev=1566649&r1=1566648&r2=1566649&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MergeNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MergeNode.java Mon Feb
10 15:10:31 2014
@@ -214,6 +214,9 @@ public final class MergeNode extends DML
             throw StandardException.newException( SQLState.LANG_SAME_EXPOSED_NAME );
         }
 
+        // don't allow derived column lists right now
+        forbidDerivedColumnLists();
+        
         // synonyms not allowed
         forbidSynonyms( dd );
 
@@ -272,6 +275,30 @@ public final class MergeNode extends DML
         return ft.getTableName().getTableName();
     }
 
+    /**
+     *<p>
+     * Because of name resolution complexities, we do not allow derived column lists
+     * on source or target tables. These lists arise in queries like the following:
+     * </p>
+     *
+     * <pre>
+     * merge into t1 r( x )
+     * using t2 on r.x = t2.a
+     * when matched then delete;
+     * 
+     * merge into t1
+     * using t2 r( x ) on t1.a = r.x
+     * when matched then delete;
+     * </pre>
+     */
+    private void    forbidDerivedColumnLists() throws StandardException
+    {
+        if ( (_sourceTable.resultColumns != null) || (_targetTable.resultColumns != null)
)
+        {
+            throw StandardException.newException( SQLState.LANG_NO_DCL_IN_MERGE );
+        }
+    }
+
     /** Neither the source nor the target table may be a synonym */
     private void    forbidSynonyms( DataDictionary dd )    throws StandardException
     {

Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml?rev=1566649&r1=1566648&r2=1566649&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml Mon Feb 10 15:10:31
2014
@@ -2296,6 +2296,11 @@ Guide.
                 <text>Synonyms are not allowed as the source or target tables of MERGE
statements.</text>
             </msg>
 
+	        <msg>
+                <name>42XAQ</name>
+                <text>The source and target tables of MERGE statements may not have
derived column lists.</text>
+            </msg>
+
             <msg>
                 <name>42Y00</name>
                 <text>Class '{0}' does not implement org.apache.derby.iapi.db.AggregateDefinition
and thus cannot be used as an aggregate expression.</text>

Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java?rev=1566649&r1=1566648&r2=1566649&view=diff
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
(original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
Mon Feb 10 15:10:31 2014
@@ -952,6 +952,7 @@ public interface SQLState {
     String LANG_NOT_NULL_CHARACTERISTICS                               = "42XAN";
     String LANG_NO_SUBQUERIES_IN_MATCHED_CLAUSE         = "42XAO";
     String LANG_NO_SYNONYMS_IN_MERGE                            = "42XAP";
+    String LANG_NO_DCL_IN_MERGE                                         = "42XAQ";
     String LANG_INVALID_USER_AGGREGATE_DEFINITION2                     = "42Y00";
 	String LANG_INVALID_CHECK_CONSTRAINT                               = "42Y01";
     // String LANG_NO_ALTER_TABLE_COMPRESS_ON_TARGET_TABLE             = "42Y02";

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java?rev=1566649&r1=1566648&r2=1566649&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java
Mon Feb 10 15:10:31 2014
@@ -73,6 +73,7 @@ public class MergeStatementTest extends 
     private static  final   String      NO_DML_IN_BEFORE_TRIGGERS = "42Z9D";
     private static  final   String      NO_SUBQUERIES_IN_MATCHED_CLAUSE = "42XAO";
     private static  final   String      NO_SYNONYMS_IN_MERGE = "42XAP";
+    private static  final   String      NO_DCL_IN_MERGE = "42XAQ";
 
     private static  final   String[]    TRIGGER_HISTORY_COLUMNS = new String[] { "ACTION",
"ACTION_VALUE" };
 
@@ -5130,6 +5131,51 @@ public class MergeStatementTest extends 
         assertResults( conn, "select * from t1_035 order by x", expectedResults, false );
     }
     
+   /**
+     * <p>
+     * Don't allow derived column lists in MERGE statements..
+     * </p>
+     */
+    public  void    test_036_derivedColumnLists()
+        throws Exception
+    {
+        Connection  dboConnection = openUserConnection( TEST_DBO );
+
+        //
+        // create schema
+        //
+        goodStatement
+            (
+             dboConnection,
+             "create table t1_036( a int )"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "create table t2_036( a int )"
+             );
+
+        // verify that derived column lists are not allowed
+        expectCompilationError
+            ( dboConnection, NO_DCL_IN_MERGE,
+              "merge into t1_036 r( x )\n" +
+              "using t2_036 on r.x = t2_036.a\n" +
+              "when matched then delete\n"
+              );
+        expectCompilationError
+            ( dboConnection, NO_DCL_IN_MERGE,
+              "merge into t1_036\n" +
+              "using t2_036 r( x ) on t1_036.a = r.x\n" +
+              "when matched then delete\n"
+              );
+
+        //
+        // drop schema
+        //
+        goodStatement( dboConnection, "drop table t2_036" );
+        goodStatement( dboConnection, "drop table t1_036" );
+    }
+    
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // ROUTINES



Mime
View raw message