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 bp...@apache.org on 2010/06/14 03:35:35 UTC
svn commit: r954344 - in /db/derby/code/trunk/java:
engine/org/apache/derby/impl/sql/execute/RenameConstantAction.java
testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java
Author: bpendleton
Date: Mon Jun 14 01:35:34 2010
New Revision: 954344
URL: http://svn.apache.org/viewvc?rev=954344&view=rev
Log:
DERBY-4693: RENAME COLUMN loses IDENTITY attributes
This change modifies the RENAME COLUMN logic so that it preserves the
autoincrement properties of the column when renaming it. Since RENAME
COLUMN more-or-less drops and re-adds the column, we need to ensure
that when the column is re-added, if it is an Autoincrement column,
we set the CREATE_AUTOINCREMENT flag that the parser sets when
initially creating the table.
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/RenameConstantAction.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/RenameConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/RenameConstantAction.java?rev=954344&r1=954343&r2=954344&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/RenameConstantAction.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/RenameConstantAction.java Mon Jun 14 01:35:34 2010
@@ -50,6 +50,7 @@ import org.apache.derby.catalog.UUID;
import org.apache.derby.iapi.services.io.FormatableBitSet;
+import org.apache.derby.impl.sql.compile.ColumnDefinitionNode;
/**
* This class describes actions that are ALWAYS performed for a
@@ -331,6 +332,11 @@ class RenameConstantAction extends DDLSi
* dependents on the column.
*/
columnDescriptor = td.getColumnDescriptor(oldObjectName);
+
+ if (columnDescriptor.isAutoincrement())
+ columnDescriptor.setAutoinc_create_or_modify_Start_Increment(
+ ColumnDefinitionNode.CREATE_AUTOINCREMENT);
+
columnPosition = columnDescriptor.getPosition();
FormatableBitSet toRename = new FormatableBitSet(td.getColumnDescriptorList().size() + 1);
toRename.set(columnPosition);
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java?rev=954344&r1=954343&r2=954344&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java Mon Jun 14 01:35:34 2010
@@ -1154,6 +1154,83 @@ public final class AlterTableTest extend
"session.logged(logged int) on commit delete rows not logged");
}
+ /**
+ * See DERBY-4693 for a case where this was broken.
+ */
+ public void testRenameAutoincrementColumn()
+ throws Exception
+ {
+ // First, the repro from the Jira issue originally logged:
+ Statement st = createStatement();
+ st.executeUpdate("create table d4693" +
+ "(a int generated always as identity, b int)");
+ JDBC.assertFullResultSet(st.executeQuery(
+ "select columnname,columnnumber,columndatatype," +
+ " autoincrementvalue," +
+ " autoincrementstart," +
+ " autoincrementinc" +
+ " from sys.syscolumns where " +
+ " columnname = 'A' and " +
+ " referenceid in (select tableid " +
+ " from sys.systables where tablename = 'D4693')"),
+ new String[][]{ {"A","1","INTEGER NOT NULL","1","1","1"} });
+ st.executeUpdate("insert into d4693 (b) values (1)");
+ st.executeUpdate("rename column d4693.a to a2");
+ JDBC.assertFullResultSet(st.executeQuery(
+ "select columnname,columnnumber,columndatatype," +
+ " autoincrementvalue," +
+ " autoincrementstart," +
+ " autoincrementinc" +
+ " from sys.syscolumns where " +
+ " columnname = 'A2' and " +
+ " referenceid in (select tableid " +
+ " from sys.systables where tablename = 'D4693')"),
+ new String[][]{ {"A2","1","INTEGER NOT NULL","2","1","1"} });
+ st.executeUpdate("insert into d4693 (b) values (2)");
+ JDBC.assertFullResultSet(st.executeQuery(
+ "select a2, b from d4693"),
+ new String[][]{ {"1", "1"}, {"2", "2"} });
+ st.executeUpdate("drop table d4693");
+
+ // Then, a few other arbitrary test cases:
+ String colspecs[] = {
+ "autoinc int generated always as identity (start with 100)",
+ "autoinc1 int generated always as identity (increment by 100)",
+ "autoinc2 int generated always as identity (start with 101, increment by 100)",
+ "a11 int generated always as identity (start with 0, increment by -1)",
+ "a21 int generated always as identity (start with +0, increment by -1)",
+ "a31 int generated always as identity (start with -1, increment by -1)",
+ "a41 int generated always as identity (start with -11, increment by +100)"
+ };
+ String cn[] = {
+ "AUTOINC", "AUTOINC1", "AUTOINC2", "A11", "A21", "A31", "A41" };
+ String val[] = {
+ "100", "1", "101", "0", "0", "-1", "-11" };
+ String start[] = {
+ "100", "1", "101", "0", "0", "-1", "-11" };
+ String inc[] = {
+ "1", "100", "100", "-1", "-1", "-1", "100" };
+ for (int i = 0; i < colspecs.length; i++)
+ {
+ st.executeUpdate("create table d4693 (" + colspecs[i] + ")");
+ checkValStartInc(st, cn[i], val[i], start[i], inc[i]);
+ st.executeUpdate("rename column d4693."+cn[i]+" to "+cn[i]+"2");
+ checkValStartInc(st, cn[i]+"2", val[i], start[i], inc[i]);
+ st.executeUpdate("drop table d4693");
+ }
+ }
+ private void checkValStartInc(Statement st, String nm, String v,
+ String s, String inc)
+ throws Exception
+ {
+ JDBC.assertFullResultSet(st.executeQuery(
+ "select autoincrementvalue,autoincrementstart,autoincrementinc" +
+ " from sys.syscolumns where columnname = '"+nm+"' and " +
+ " referenceid in (select tableid " +
+ " from sys.systables where tablename = 'D4693')"),
+ new String[][]{ {v, s, inc} });
+ }
+
public void testAlterColumn() throws Exception {
Statement st = createStatement();
createTestObjects(st);