db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject svn commit: r960222 - in /db/derby/code/branches/10.5: ./ java/engine/org/apache/derby/impl/sql/compile/ java/testing/ java/testing/org/apache/derbyTesting/functionTests/master/ java/testing/org/apache/derbyTesting/functionTests/suites/ java/testing/or...
Date Sat, 03 Jul 2010 14:26:33 GMT
Author: mikem
Date: Sat Jul  3 14:26:32 2010
New Revision: 960222

URL: http://svn.apache.org/viewvc?rev=960222&view=rev
Log:
DERBY-4244: ALTER TABLE ASSERT in ADD COLUMN with autocommit off

backported svn #795459 from trunk to 10.5 branch.  Also backported the
AlterTableTest.java from trunk so that test for this issue could be 
run.

This patch was contributed by Eranda Sooriyabandara (070468D at gmail dot com)

An ALTER TABLE ... ADD COLUMN statement which specifies to add a column to
a table may also include any column constraints which apply to that column.
For example, to add a column to a table and at the same time indicate that
the column should be the primary key of the table, this statement is used:

   alter table t0 add column c2 int not null default 0 primary key;

If the table already contains a primary key, this statement fails, as the
table cannot have more than one primary key. However, the check for the
duplicate primary key was occurring at execution time, *after* the column
had already been added to the table. Then, during that same transaction,
subsequent ALTER TABLE statements affecting that table failed with internal
ASSERT messages because the data dictionary data structures were inconsistent.

This patch adds logic to the compilation processing of the ALTER TABLE
statement to check for a duplicate PRIMARY KEY constraint at compile
time, before the ALTER TABLE statement has begun execution. This way, when
such a duplicate constraint is rejected, the rejection occurs prior to
execution of the table, allowing for more straightforward cleanup.

The patch also re-enables a portion of the AlterTableTest, which had been
disabled due to this problem. 


Added:
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java
      - copied unchanged from r791027, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java
Removed:
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/master/altertable.out
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/altertable.sql
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/altertable_derby.properties
Modified:
    db/derby/code/branches/10.5/   (props changed)
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/AlterTableNode.java
    db/derby/code/branches/10.5/java/testing/README.htm
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java

Propchange: db/derby/code/branches/10.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Jul  3 14:26:32 2010
@@ -1,2 +1,2 @@
 /db/derby/code/branches/10.6:957000
-/db/derby/code/trunk:757811,769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,792434,793089,793588,794106,794303,794955,795166,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,829022,832379,833430,835286,881074,881444,882732,884163,887246,892912,897161,898635,901165,901648,901760,903108,908418,909176,911315,915733,916075,916897,918359,921028,927430,928065,942286,942476,942480,942587,946794,948045,948069,951346,954748,955001,955634,956075,956445,956659,958163,959550
+/db/derby/code/trunk:757811,769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,791027,792434,793089,793588,794106,794303,794955,795166,795459,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,829022,832379,833430,835286,881074,881444,882732,884163,887246,892912,897161,898635,901165,901648,901760,903108,908418,909176,911315,915733,916075,916897,918359,921028,927430,928065,942286,942476,942480,942587,946794,948045,948069,951346,954748,955001,955634,956075,956445,956659,958163,959550

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/AlterTableNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/AlterTableNode.java?rev=960222&r1=960221&r2=960222&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/AlterTableNode.java
(original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/AlterTableNode.java
Sat Jul  3 14:26:32 2010
@@ -32,6 +32,7 @@ import org.apache.derby.iapi.error.Stand
 import org.apache.derby.iapi.sql.compile.C_NodeTypes;
 
 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
+import org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList;
 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
 import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
@@ -41,6 +42,7 @@ import org.apache.derby.iapi.types.Strin
 
 import org.apache.derby.impl.sql.execute.ColumnInfo;
 import org.apache.derby.impl.sql.execute.ConstraintConstantAction;
+import org.apache.derby.impl.sql.execute.CreateConstraintConstantAction;
 
 /**
  * A AlterTableNode represents a DDL statement that alters a table.
@@ -511,6 +513,31 @@ public class AlterTableNode extends DDLS
 
 			tableElementList.genConstraintActions(false, conActions, getRelativeName(), schemaDescriptor,
 												  getDataDictionary());
+
+			for (int conIndex = 0; conIndex < conActions.length; conIndex++)
+			{
+				ConstraintConstantAction cca = conActions[conIndex];
+
+				if (cca instanceof CreateConstraintConstantAction)
+				{
+					int constraintType = cca.getConstraintType();
+					if (constraintType == DataDictionary.PRIMARYKEY_CONSTRAINT)
+					{
+						DataDictionary dd = getDataDictionary();
+						// Check to see if a constraint of the same type 
+						// already exists
+						ConstraintDescriptorList cdl = 
+                                dd.getConstraintDescriptors(baseTable);
+
+						if (cdl.getPrimaryKey() != null)
+						{
+							throw StandardException.newException(
+                                    SQLState.LANG_ADD_PRIMARY_KEY_FAILED1, 
+                                    baseTable.getQualifiedName());
+						}
+					}
+				}
+			}
 		}
 	}
 	  

Modified: db/derby/code/branches/10.5/java/testing/README.htm
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/README.htm?rev=960222&r1=960221&r2=960222&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/README.htm (original)
+++ db/derby/code/branches/10.5/java/testing/README.htm Sat Jul  3 14:26:32 2010
@@ -1038,13 +1038,6 @@ Now run the suite's tests<br>
 Run the tests...<br>
 Execute command: java -DjavaCmd=java
 -Doutputdir=C:\derbyt1\derbylang\derbylang
--Dtopsuitedir=C:\derbyt1\derbylang -Dtoprepo<br>
-rtdir=C:\derbyt1\derbylang -Drundir=C:\derbyt1
--Dsuitename=derbylang:derbylang -Dtopsuitename=derbylang
-org.apache.derbyTesting.functionTests.harness.RunTest
-lang/altertable.sql<br>
-Execute command: java -DjavaCmd=java
--Doutputdir=C:\derbyt1\derbylang\derbylang
 -Dtopsuitedir=C:\derbyt1\derbylang -Dtopreportdir=C:\derbyt1\derbylang
 -Drundir=C:\derbyt1 -Dsuitename=derbylang:derbylang
 -Dtopsuitename=derbylang

Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall?rev=960222&r1=960221&r2=960222&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall
(original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall
Sat Jul  3 14:26:32 2010
@@ -1,7 +1,6 @@
 lang/DB2IsolationLevels.sql
 lang/LOBDB2compatibility.sql
 lang/aggregateOptimization.sql
-lang/altertable.sql
 lang/autoincrement.sql
 lang/checkConstraint.sql
 lang/columnDefaults.sql

Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java?rev=960222&r1=960221&r2=960222&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
(original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
Sat Jul  3 14:26:32 2010
@@ -60,6 +60,7 @@ public class _Suite extends BaseTestCase
         // suite.addTest(largeCodeGen.suite());
 
         suite.addTest(AnsiTrimTest.suite());
+        suite.addTest(AlterTableTest.suite());
         suite.addTest(CreateTableFromQueryTest.suite());
         suite.addTest(CompressTableTest.suite());
         suite.addTest(DatabaseClassLoadingTest.suite());



Mime
View raw message