You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ma...@apache.org on 2014/03/10 07:23:58 UTC

svn commit: r1575839 - in /db/derby/code/branches/10.9: ./ java/engine/org/apache/derby/impl/sql/compile/ java/testing/org/apache/derbyTesting/functionTests/tests/lang/

Author: mamta
Date: Mon Mar 10 06:23:58 2014
New Revision: 1575839

URL: http://svn.apache.org/r1575839
Log:
DERBY-6361(Valid statements rejected if Derby has not implicitly created the current user's schema.)

Backporting to 10.9


Modified:
    db/derby/code/branches/10.9/   (props changed)
    db/derby/code/branches/10.9/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java
    db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
    db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/lang/build.xml

Propchange: db/derby/code/branches/10.9/
------------------------------------------------------------------------------
  Merged /db/derby/code/trunk:r1532997
  Merged /db/derby/code/branches/10.10:r1575635

Modified: db/derby/code/branches/10.9/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.9/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java?rev=1575839&r1=1575838&r2=1575839&view=diff
==============================================================================
--- db/derby/code/branches/10.9/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java (original)
+++ db/derby/code/branches/10.9/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java Mon Mar 10 06:23:58 2014
@@ -470,8 +470,8 @@ abstract class DMLModStatementNode exten
                 // current schema at the time that the table was
                 // created/altered. See DERBY-3945.
                 //
-                SchemaDescriptor    originalCurrentSchema = getSchemaDescriptor( di.getOriginalCurrentSchema(), true );
-                compilerContext.pushCompilationSchema( originalCurrentSchema );
+                compilerContext.pushCompilationSchema(
+                    getSchemaDescriptor(di.getOriginalCurrentSchema(), false));
 
 				try {
                     bindRowScopedExpression( getNodeFactory(), getContextManager(), targetTableDescriptor, sourceRCL, generationClause );

Modified: db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java?rev=1575839&r1=1575838&r2=1575839&view=diff
==============================================================================
--- db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java (original)
+++ db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java Mon Mar 10 06:23:58 2014
@@ -5574,6 +5574,73 @@ public class GeneratedColumnsTest extend
 
     }
 
+    /**
+     * Verify that generated columns can be used even if the schema in which
+     * the generated column was added does not exist. Regression test case
+     * for DERBY-6361.
+     */
+    public void test_6361_compilationSchemaDoesNotExist() throws SQLException {
+        String user = "D6163_USER_WITHOUT_SCHEMA";
+        Connection conn = openUserConnection(user);
+        conn.setAutoCommit(false);
+
+        // Verify that the user does not have a schema.
+        JDBC.assertEmpty(conn.getMetaData().getSchemas(null, user));
+
+        Statement s = conn.createStatement();
+
+        s.execute("create table d6361.t(x int, y generated always as (-x))");
+
+        // This statement used to fail with schema does not exist.
+        s.execute("insert into d6361.t(x) values 1");
+
+        // This statement used to fail with schema does not exist.
+        s.execute("alter table d6361.t add column z generated always as (x+1)");
+
+        s.execute("insert into d6361.t(x) values 2");
+
+        JDBC.assertFullResultSet(
+                s.executeQuery("select * from d6361.t order by x"),
+                new String[][] {{"1", "-1", "2"}, {"2", "-2", "3"}});
+
+        // Verify that the user still does not have a schema.
+        JDBC.assertEmpty(conn.getMetaData().getSchemas(null, user));
+
+        s.close();
+        JDBC.cleanup(conn);
+    }
+
+    /**
+     * Verify that generated columns work even if the compilation schema at
+     * the time of adding the generated columns is dropped. Regression test
+     * case for DERBY-6361.
+     */
+    public void test_6361_compilationSchemaDeleted() throws SQLException {
+        setAutoCommit(false);
+        Statement s = createStatement();
+        s.execute("create schema d6361_s1");
+        s.execute("create schema d6361_s2");
+
+        // Create a generated column in a table that lives in schema S1.
+        // Declare the generated column while the current schema is S2.
+        // Create generated columns both with CREATE TABLE and with ALTER
+        // TABLE so that we test both code paths.
+        s.execute("set schema d6361_s2");
+        s.execute("create table d6361_s1.t(x int, y generated always as (-x))");
+        s.execute("alter table d6361_s1.t "
+                + "add column z generated always as (x+1)");
+
+        // Then drop the schema that the generated columns were added from.
+        s.execute("set schema d6361_s1");
+        s.execute("drop schema d6361_s2 restrict");
+
+        // This statement used to fail with schema does not exist.
+        s.execute("insert into t(x) values 1");
+
+        JDBC.assertFullResultSet(s.executeQuery("select * from t"),
+                                 new String[][] {{"1", "-1", "2"}});
+    }
+
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // MINIONS

Modified: db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/lang/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/lang/build.xml?rev=1575839&r1=1575838&r2=1575839&view=diff
==============================================================================
--- db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/lang/build.xml (original)
+++ db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/lang/build.xml Mon Mar 10 06:23:58 2014
@@ -59,13 +59,35 @@
 <!--             ============ Begin Targets ==============                -->
  
   <target name="FTOtestsubdir" depends="compilett4,copyfiles"/>
+  <target name="compilet0">
+    <javac
+      source="${compilerLevel16}"
+      target="${compilerLevel16}"
+      bootclasspath="${empty}"
+      nowarn="on"
+      debug="true"
+      depend="${depend}"
+      deprecation="${deprecation}"
+      optimize="${optimize}"
+      proceed="${proceed}"
+      verbose="${verbose}"
+      srcdir="${derby.testing.src.dir}"
+      destdir="${out.dir}">
+      <classpath>
+        <pathelement path="${java16compile.classpath}"/>
+      	<pathelement path="${junit}"/>
+      </classpath>
+      <include name="${this.dir}/GeneratedColumnsTest.java"/>
+    </javac>
+  </target> 
 
   <!-- mkdir / init target may not be necessary, just here for reference... -->
   <target name="init">
     <mkdir dir="${out.dir}/${derby.testing.functest.dir}/tests/lang"/>
   </target>
 
-  <target name="compilet1" >
+
+  <target name="compilet1" depends="compilet0">
     <javac
       source="1.4"
       target="1.4"