db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1580889 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_11.java
Date Mon, 24 Mar 2014 15:47:54 GMT
Author: rhillegas
Date: Mon Mar 24 15:47:53 2014
New Revision: 1580889

URL: http://svn.apache.org/r1580889
Log:
DERBY-3155: Forbid MERGE statements in soft-upgraded databases; commit derby-3155-52-aa-upgrade.diff.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_11.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj?rev=1580889&r1=1580888&r2=1580889&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj Mon Mar
24 15:47:53 2014
@@ -3663,6 +3663,8 @@ mergeStatement() throws StandardExceptio
     searchCondition = joinCondition()
     matchingClauses = matchingClauseList()
 	{
+        checkVersion( DataDictionary.DD_VERSION_DERBY_10_11, "MERGE" );
+
 		setUpAndLinkParameters();
 
         return new MergeNode

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_11.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_11.java?rev=1580889&r1=1580888&r2=1580889&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_11.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_11.java
Mon Mar 24 15:47:53 2014
@@ -20,8 +20,13 @@ limitations under the License.
 */
 package org.apache.derbyTesting.functionTests.tests.upgradeTests;
 
+import java.sql.Connection;
+import java.sql.PreparedStatement;
 import java.sql.SQLException;
+import java.sql.SQLWarning;
 import java.sql.Statement;
+import java.util.Arrays;
+import java.util.ArrayList;
 import junit.framework.Test;
 import junit.framework.TestSuite;
 import org.apache.derbyTesting.junit.JDBC;
@@ -42,6 +47,7 @@ public class Changes10_11 extends Upgrad
     private static  final   String  SYNTAX_ERROR = "42X01";
     private static  final   String  HARD_UPGRADE_REQUIRED = "XCL47";
     private static  final   String  NOT_IMPLEMENTED = "0A000";
+    private static  final   String  NO_ROWS_AFFECTED = "02000";
 
     //////////////////////////////////////////////////////////////////
     //
@@ -371,4 +377,81 @@ public class Changes10_11 extends Upgrad
             commit();
         }
     }
+
+    public void testMerge() throws Exception
+    {
+        String mergeStatement =
+            "merge into targetTable t using sourceTable s on t.a = s.a\n" +
+            "when matched then delete\n";
+
+        Statement s = createStatement();
+        switch (getPhase())
+        {
+            case PH_CREATE:
+                s.execute("create table targetTable( a int )");
+                s.execute("create table sourceTable( a int )");
+                assertCompileError( SYNTAX_ERROR, mergeStatement );
+                break;
+            case PH_SOFT_UPGRADE:
+                assertCompileError( HARD_UPGRADE_REQUIRED,  mergeStatement );
+                break;
+            case PH_POST_SOFT_UPGRADE:
+                assertCompileError( SYNTAX_ERROR, mergeStatement );
+                break;
+            case PH_HARD_UPGRADE:
+                expectExecutionWarning( getConnection(), NO_ROWS_AFFECTED, mergeStatement
);
+                break;
+        }
+    }
+
+    /**
+     * Assert that the statement text, when executed, raises a warning.
+     */
+    private void    expectExecutionWarning( Connection conn, String sqlState, String query
)
+        throws Exception
+    {
+        expectExecutionWarnings( conn, new String[] { sqlState }, query );
+    }
+
+    /**
+     * Assert that the statement text, when executed, raises a warning.
+     */
+    private void    expectExecutionWarnings( Connection conn, String[] sqlStates, String
query )
+        throws Exception
+    {
+        println( "\nExpecting warnings " + fill( sqlStates ).toString() + " when executing:\n\t"
 );
+        PreparedStatement   ps = chattyPrepare( conn, query );
+
+        ps.execute();
+
+        int idx = 0;
+
+        for ( SQLWarning sqlWarning = ps.getWarnings(); sqlWarning != null; sqlWarning =
sqlWarning.getNextWarning() )
+        {
+            String          actualSQLState = sqlWarning.getSQLState();
+
+            if ( idx >= sqlStates.length )
+            {
+                fail( "Got more warnings than we expected." );
+            }
+
+            String  expectedSqlState = sqlStates[ idx++ ];
+
+            assertEquals( expectedSqlState, actualSQLState );
+        }
+
+        assertEquals( idx, sqlStates.length );
+
+        ps.close();
+    }
+
+    /**
+     * <p>
+     * Fill an ArrayList from an array.
+     * </p>
+     */
+    protected <T> ArrayList<T> fill( T[] raw )
+    {
+        return new ArrayList<T>(Arrays.asList(raw));
+    }
 }



Mime
View raw message