db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1808071 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj testing/org/apache/derbyTesting/functionTests/tests/lang/AutoIncrementTest.java
Date Tue, 12 Sep 2017 00:05:28 GMT
Author: rhillegas
Date: Tue Sep 12 00:05:28 2017
New Revision: 1808071

URL: http://svn.apache.org/viewvc?rev=1808071&view=rev
Log:
DERBY-6959: Require Standard SET keyword when changing the cycling behavior of an identity
column; commit derby-6959-01-ab-requireSETkeyword.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/lang/AutoIncrementTest.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=1808071&r1=1808070&r2=1808071&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 Tue Sep
12 00:05:28 2017
@@ -13733,6 +13733,7 @@ columnAlterClause(String columnName) thr
 	long				autoIncrementRestartWith = 1;
 	DataTypeDescriptor	typeDescriptor = null;
 	int                 alterKind;
+    TableElementNode    identityAlteration;
 }
 {
 	LOOKAHEAD( {getToken(2).kind == DATA} )
@@ -13747,24 +13748,10 @@ columnAlterClause(String columnName) thr
                                  getContextManager());
 	}
 |
-	LOOKAHEAD( {getToken(2).kind == GENERATED} )
-	<SET> <GENERATED> alterKind = alterGeneratedColumn()
-	{
-		checkVersion(DataDictionary.DD_VERSION_DERBY_10_11, "ALTER TABLE ALTER COLUMN SET GENERATED");
-        return
-            new ModifyColumnNode(alterKind,
-                                 columnName,
-                                 null,
-                                 null,
-                                 null,
-                                 getContextManager());
-	}
-|
-	LOOKAHEAD( {getToken(2).kind == INCREMENT} )
-	<SET> <INCREMENT> <BY> autoIncrementIncrement = exactNumber()
+	<RESTART> <WITH> autoIncrementRestartWith = exactNumber()
 	{
-		autoIncrementInfo[QueryTreeNode.AUTOINCREMENT_INC_INDEX] = autoIncrementIncrement;
-		autoIncrementInfo[QueryTreeNode.AUTOINCREMENT_CREATE_MODIFY] = ColumnDefinitionNode.MODIFY_AUTOINCREMENT_INC_VALUE;
+		autoIncrementInfo[QueryTreeNode.AUTOINCREMENT_START_INDEX] = autoIncrementRestartWith;
+		autoIncrementInfo[QueryTreeNode.AUTOINCREMENT_CREATE_MODIFY] = ColumnDefinitionNode.MODIFY_AUTOINCREMENT_RESTART_VALUE;
         return
             new ModifyColumnNode(ModifyColumnNode.K_MODIFY_COLUMN_DEFAULT,
                                  columnName,
@@ -13774,43 +13761,23 @@ columnAlterClause(String columnName) thr
                                  getContextManager());
 	}
 |
-	<CYCLE> 
+	LOOKAHEAD( {getToken(2).kind == GENERATED} )
+	<SET> <GENERATED> alterKind = alterGeneratedColumn()
 	{
-		autoIncrementInfo[QueryTreeNode.AUTOINCREMENT_CYCLE] = 1;
-		autoIncrementInfo[QueryTreeNode.AUTOINCREMENT_CREATE_MODIFY] = ColumnDefinitionNode.MODIFY_AUTOINCREMENT_CYCLE_VALUE;
+		checkVersion(DataDictionary.DD_VERSION_DERBY_10_11, "ALTER TABLE ALTER COLUMN SET GENERATED");
         return
-            new ModifyColumnNode(ModifyColumnNode.K_MODIFY_COLUMN_DEFAULT,
+            new ModifyColumnNode(alterKind,
                                  columnName,
                                  null,
                                  null,
-                                 autoIncrementInfo,
-                                 getContextManager());
-	}
-|
-	<NO> <CYCLE> 
-	{
-		autoIncrementInfo[QueryTreeNode.AUTOINCREMENT_CYCLE] = 0;
-		autoIncrementInfo[QueryTreeNode.AUTOINCREMENT_CREATE_MODIFY] = ColumnDefinitionNode.MODIFY_AUTOINCREMENT_CYCLE_VALUE;
-        return
-            new ModifyColumnNode(ModifyColumnNode.K_MODIFY_COLUMN_DEFAULT,
-                                 columnName,
-                                 null,
                                  null,
-                                 autoIncrementInfo,
                                  getContextManager());
 	}
 |
-	<RESTART> <WITH> autoIncrementRestartWith = exactNumber()
+	LOOKAHEAD( {(getToken(1).kind == SET) && (getToken(2).kind != _DEFAULT) &&
(getToken(2).kind != NOT)} )
+	<SET> identityAlteration = columnAlterIdentityClause(columnName)
 	{
-		autoIncrementInfo[QueryTreeNode.AUTOINCREMENT_START_INDEX] = autoIncrementRestartWith;
-		autoIncrementInfo[QueryTreeNode.AUTOINCREMENT_CREATE_MODIFY] = ColumnDefinitionNode.MODIFY_AUTOINCREMENT_RESTART_VALUE;
-        return
-            new ModifyColumnNode(ModifyColumnNode.K_MODIFY_COLUMN_DEFAULT,
-                                 columnName,
-                                 null,
-                                 null,
-                                 autoIncrementInfo,
-                                 getContextManager());
+        return identityAlteration;
 	}
 |
 	LOOKAHEAD( {getToken(1).kind == WITH || getToken(1).kind == _DEFAULT ||
@@ -13874,6 +13841,64 @@ columnAlterClause(String columnName) thr
 	}
 }
 
+/*
+ * Various variants of the ALTER TABLE ALTER COLUMN SET statement.
+ *
+ * By the time we get here, we've parsed
+ *    ALTER TABLE tablename ALTER [COLUMN] columnname SET
+ *		INCREMENT BY increment_value
+ *      [NO] CYCLE
+ */
+TableElementNode
+columnAlterIdentityClause(String columnName) throws StandardException :
+{
+	ValueNode	defaultNode;
+	long[]				autoIncrementInfo = new long[5];
+	long				autoIncrementIncrement = 1;
+	long				autoIncrementCycle=0;
+	int                 alterKind;
+}
+{
+	<INCREMENT> <BY> autoIncrementIncrement = exactNumber()
+	{
+		autoIncrementInfo[QueryTreeNode.AUTOINCREMENT_INC_INDEX] = autoIncrementIncrement;
+		autoIncrementInfo[QueryTreeNode.AUTOINCREMENT_CREATE_MODIFY] = ColumnDefinitionNode.MODIFY_AUTOINCREMENT_INC_VALUE;
+        return
+            new ModifyColumnNode(ModifyColumnNode.K_MODIFY_COLUMN_DEFAULT,
+                                 columnName,
+                                 null,
+                                 null,
+                                 autoIncrementInfo,
+                                 getContextManager());
+	}
+|
+	<CYCLE> 
+	{
+		autoIncrementInfo[QueryTreeNode.AUTOINCREMENT_CYCLE] = 1;
+		autoIncrementInfo[QueryTreeNode.AUTOINCREMENT_CREATE_MODIFY] = ColumnDefinitionNode.MODIFY_AUTOINCREMENT_CYCLE_VALUE;
+        return
+            new ModifyColumnNode(ModifyColumnNode.K_MODIFY_COLUMN_DEFAULT,
+                                 columnName,
+                                 null,
+                                 null,
+                                 autoIncrementInfo,
+                                 getContextManager());
+	}
+|
+	<NO> <CYCLE> 
+	{
+		autoIncrementInfo[QueryTreeNode.AUTOINCREMENT_CYCLE] = 0;
+		autoIncrementInfo[QueryTreeNode.AUTOINCREMENT_CREATE_MODIFY] = ColumnDefinitionNode.MODIFY_AUTOINCREMENT_CYCLE_VALUE;
+        return
+            new ModifyColumnNode(ModifyColumnNode.K_MODIFY_COLUMN_DEFAULT,
+                                 columnName,
+                                 null,
+                                 null,
+                                 autoIncrementInfo,
+                                 getContextManager());
+	}
+}
+
 /*
  * Various variants of the ALTER TABLE ALTER COLUMN SET GENERATED statement.
  *

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AutoIncrementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AutoIncrementTest.java?rev=1808071&r1=1808070&r2=1808071&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AutoIncrementTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AutoIncrementTest.java
Tue Sep 12 00:05:28 2017
@@ -1051,7 +1051,7 @@ public class AutoIncrementTest extends B
 		Statement s=createStatement();
 		ResultSet rs;
 
-		s.execute("alter table cycle1 alter column rec21 CYCLE");
+		s.execute("alter table cycle1 alter column rec21 set CYCLE");
 
 		rs=s.executeQuery("select COLUMNNAME, AUTOINCREMENTVALUE, AUTOINCREMENTSTART, AUTOINCREMENTINC,
AUTOINCREMENTCYCLE " +
 				"       from sys.syscolumns where COLUMNNAME = 'REC21'");
@@ -1097,8 +1097,8 @@ public class AutoIncrementTest extends B
 		assertStatementError("42X01",s,"alter table restartt1 alter column c12 restart with cycle");
 
         // c12 is not an autoincrement column:
-		assertStatementError("42837",s,"alter table restartt1 alter column c12 cycle");
-		assertStatementError("42837",s,"alter table restartt1 alter column c12 no cycle");
+		assertStatementError("42837",s,"alter table restartt1 alter column c12 set cycle");
+		assertStatementError("42837",s,"alter table restartt1 alter column c12 set no cycle");
 
         // Demonstrate that we can change column rec11 from NO CYCLE to CYCLE
         // and back to NO CYCLE, verifying by looking at SYSCOLUMNS:
@@ -1107,14 +1107,14 @@ public class AutoIncrementTest extends B
 		String[][]expectedRows = new String[][]{{"REC11","false"}};
 		JDBC.assertFullResultSet(rs,expectedRows);
 
-        s.execute("alter table restartt1 alter column rec11 cycle");
+        s.execute("alter table restartt1 alter column rec11 set cycle");
 
 		rs=s.executeQuery("select COLUMNNAME, AUTOINCREMENTCYCLE " +
                           "       from sys.syscolumns where COLUMNNAME = 'REC11'");
 		expectedRows = new String[][]{{"REC11","true"}};
 		JDBC.assertFullResultSet(rs,expectedRows);
 
-        s.execute("alter table restartt1 alter column rec11 no cycle");
+        s.execute("alter table restartt1 alter column rec11 set no cycle");
 
 		rs=s.executeQuery("select COLUMNNAME, AUTOINCREMENTCYCLE " +
                           "       from sys.syscolumns where COLUMNNAME = 'REC11'");



Mime
View raw message