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 ka...@apache.org on 2013/10/17 09:46:40 UTC
svn commit: r1532997 - in /db/derby/code/trunk/java:
engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java
testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
Author: kahatlen
Date: Thu Oct 17 07:46:39 2013
New Revision: 1532997
URL: http://svn.apache.org/r1532997
Log:
DERBY-6361: Valid statements rejected if Derby has not implicitly
created the current user's schema.
Make compilation of the generation clause accept that the original
compilation schema does not exist.
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/GeneratedColumnsTest.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=1532997&r1=1532996&r2=1532997&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 Oct 17 07:46:39 2013
@@ -457,8 +457,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(
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java?rev=1532997&r1=1532996&r2=1532997&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java Thu Oct 17 07:46:39 2013
@@ -22,21 +22,14 @@
package org.apache.derbyTesting.functionTests.tests.lang;
import java.sql.SQLException;
-import java.sql.SQLWarning;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
-import java.sql.DriverManager;
import java.util.ArrayList;
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.apache.derby.iapi.util.StringUtil;
import org.apache.derby.catalog.DefaultInfo;
-import org.apache.derbyTesting.junit.BaseJDBCTestCase;
-import org.apache.derbyTesting.junit.JDBC;
-import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
-import org.apache.derbyTesting.junit.JDBC;
import org.apache.derbyTesting.junit.TestConfiguration;
import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
import org.apache.derbyTesting.junit.JDBC;
@@ -5633,6 +5626,73 @@ public class GeneratedColumnsTest extend
false
);
}
+
+ /**
+ * 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"}});
+ }
///////////////////////////////////////////////////////////////////////////////////
//