Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 093351135D for ; Mon, 24 Mar 2014 15:48:24 +0000 (UTC) Received: (qmail 44727 invoked by uid 500); 24 Mar 2014 15:48:23 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 44625 invoked by uid 500); 24 Mar 2014 15:48:18 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 44596 invoked by uid 99); 24 Mar 2014 15:48:16 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Mar 2014 15:48:16 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Mar 2014 15:48:14 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 3557A238890D; Mon, 24 Mar 2014 15:47:54 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: derby-commits@db.apache.org From: rhillegas@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140324154754.3557A238890D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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(); + } + + /** + *

+ * Fill an ArrayList from an array. + *

+ */ + protected ArrayList fill( T[] raw ) + { + return new ArrayList(Arrays.asList(raw)); + } }