Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 51493 invoked from network); 7 Jan 2010 00:09:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 7 Jan 2010 00:09:50 -0000 Received: (qmail 47208 invoked by uid 500); 7 Jan 2010 00:09:50 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 47148 invoked by uid 500); 7 Jan 2010 00:09:50 -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 47139 invoked by uid 99); 7 Jan 2010 00:09:49 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jan 2010 00:09:49 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.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; Thu, 07 Jan 2010 00:09:49 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id AD2C423888E7; Thu, 7 Jan 2010 00:09:28 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r896722 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java testing/org/apache/derbyTesting/functionTests/tests/lang/SynonymTest.java Date: Thu, 07 Jan 2010 00:09:28 -0000 To: derby-commits@db.apache.org From: bpendleton@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100107000928.AD2C423888E7@eris.apache.org> Author: bpendleton Date: Thu Jan 7 00:09:28 2010 New Revision: 896722 URL: http://svn.apache.org/viewvc?rev=896722&view=rev Log: DERBY-4110: Deleting from a table with its synonym throws an exception When building the ResultColumnList that is used to tie together the search results from the WHERE clause with the processing of the DELETE, the result columns will be bound against the exposed table name of the table named in the DELETE statement, so if the statement used a synonymTableName, then the result column list should manufacture column references which use a synonymTableName as well. Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SynonymTest.java Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java?rev=896722&r1=896721&r2=896722&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java Thu Jan 7 00:09:28 2010 @@ -361,7 +361,7 @@ (FromBaseTable) (getNodeFactory().getNode( C_NodeTypes.FROM_BASE_TABLE, - targetTableName, + synonymTableName != null ? synonymTableName : targetTableName, null, null, null, Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SynonymTest.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SynonymTest.java?rev=896722&r1=896721&r2=896722&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SynonymTest.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SynonymTest.java Thu Jan 7 00:09:28 2010 @@ -27,6 +27,7 @@ import junit.framework.TestSuite; import org.apache.derbyTesting.junit.BaseJDBCTestCase; +import org.apache.derbyTesting.junit.CleanDatabaseTestSetup; /** * Synonym testing using junit @@ -45,7 +46,7 @@ */ public static Test suite() { TestSuite suite = new TestSuite(SynonymTest.class, "SynonymTest"); - return suite; + return new CleanDatabaseTestSetup(suite); } /** @@ -68,4 +69,27 @@ stmt.executeUpdate("drop synonym mySyn"); stmt.close(); } + + /** + * Test that synonyms are dereferenced properly for a searched DELETE. + * + * This test verifies that DERBY-4110 is fixed. + */ + public void testSynonymsInSearchedDeleteDERBY4110() + throws SQLException + { + Statement st = createStatement(); + st.executeUpdate("create schema test1"); + st.executeUpdate("create schema test2"); + st.executeUpdate("create table test1.t1 ( id bigint not null )"); + st.executeUpdate("insert into test1.t1 values (1),(2)"); + st.executeUpdate("create synonym test2.t1 for test1.t1"); + st.executeUpdate("create unique index idx4110 on test1.t1 (id)"); + st.executeUpdate("set schema test2"); + st.executeUpdate("delete from t1 where id = 2"); // DERBY-4110 here + st.executeUpdate("drop synonym test2.t1"); + st.executeUpdate("drop table test1.t1"); + st.executeUpdate("drop schema test2 restrict"); + st.executeUpdate("drop schema test1 restrict"); + } }