db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r637244 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ engine/org/apache/derby/impl/sql/execute/ engine/org/apache/derby/loc/ shared/org/apache/derby/shared/common/reference/ testing/org/apache/derbyTesting/functi...
Date Fri, 14 Mar 2008 20:16:35 GMT
Author: kmarsden
Date: Fri Mar 14 13:16:33 2008
New Revision: 637244

URL: http://svn.apache.org/viewvc?rev=637244&view=rev
Log:
DERBY-3523 sql states (X0Y63, X0Y63, X0Y63.S) related to nulls in unique constraints are associated
with wrong message texts

Introduced alternate message text for soft upgrade.

Contributed by Anurag Shekhar -  anurag dot shekhar at sun dot com


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/altertable.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/db2Compatibility.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/nulls.out

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java?rev=637244&r1=637243&r2=637244&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java
Fri Mar 14 13:16:33 2008
@@ -209,8 +209,13 @@
 					((existingConstraint.getConstraintType() == 
 					 DataDictionary.PRIMARYKEY_CONSTRAINT)))
 				{
-                    throw StandardException.newException(
-                         SQLState.LANG_MODIFY_COLUMN_EXISTING_CONSTRAINT, name);
+					String errorState = 
+						(getLanguageConnectionContext().getDataDictionary()
+								.checkVersion(DataDictionary.DD_VERSION_DERBY_10_4, 
+								null))
+						? SQLState.LANG_MODIFY_COLUMN_EXISTING_PRIMARY_KEY
+						: SQLState.LANG_MODIFY_COLUMN_EXISTING_CONSTRAINT;
+					throw StandardException.newException(errorState, name);
 				}
 				// unique key or primary key.
 				ConstraintDescriptorList 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java?rev=637244&r1=637243&r2=637244&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java
Fri Mar 14 13:16:33 2008
@@ -1070,7 +1070,13 @@
             // todo dtd may be null if the column does not exist, we should check that first
             if (dtd != null && dtd.isNullable())
             {
-                throw StandardException.newException(SQLState.LANG_DB2_ADD_UNIQUE_OR_PRIMARY_KEY_ON_NULL_COLS,
colName);
+                String errorState = 
+                   (getLanguageConnectionContext().getDataDictionary()
+                        .checkVersion(DataDictionary.DD_VERSION_DERBY_10_4, null))
+                    ? SQLState.LANG_ADD_PRIMARY_KEY_ON_NULL_COLS
+                    : SQLState.LANG_DB2_ADD_UNIQUE_OR_PRIMARY_KEY_ON_NULL_COLS;
+
+                throw StandardException.newException(errorState, colName);
             }
         }
     }

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=637244&r1=637243&r2=637244&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 Fri Mar
14 13:16:33 2008
@@ -313,10 +313,10 @@
 		@param version Data Dictionary major version (DataDictionary.DD_ constant)
 		@param feature SQL Feature name, for error text.
 	*/
-	private void checkVersion(int version, String feature) throws StandardException
+	private boolean checkVersion(int version, String feature) throws StandardException
 	{
-		getLanguageConnectionContext().getDataDictionary().checkVersion(
-				version, feature);
+		return getLanguageConnectionContext()
+				.getDataDictionary().checkVersion(version, feature);
 	}
 
     /**
@@ -11876,7 +11876,10 @@
 				String primaryKeyColumnName = ((ResultColumn) uniqueColumnList.elementAt(index)).getName();
 				if (explicitlyNullableColumnsList.contains(primaryKeyColumnName))
 				{
-					String errorState = SQLState.LANG_DB2_ADD_UNIQUE_OR_PRIMARY_KEY_ON_NULL_COLS;
+					String errorState = 
+						(checkVersion (DataDictionary.DD_VERSION_DERBY_10_4, null))
+							? SQLState.LANG_ADD_PRIMARY_KEY_ON_NULL_COLS
+							: SQLState.LANG_DB2_ADD_UNIQUE_OR_PRIMARY_KEY_ON_NULL_COLS;
 					throw StandardException.newException(errorState, primaryKeyColumnName);
 				}
 			}
@@ -11913,7 +11916,11 @@
 		//a column-level constraint of primary key on it will result in an error.
 		if (explicitNull) 
 		{
-			String errorState = SQLState.LANG_DB2_ADD_UNIQUE_OR_PRIMARY_KEY_ON_NULL_COLS;
+			String errorState = 
+				(checkVersion (DataDictionary.DD_VERSION_DERBY_10_4, null))
+					? SQLState.LANG_ADD_PRIMARY_KEY_ON_NULL_COLS
+					: SQLState.LANG_DB2_ADD_UNIQUE_OR_PRIMARY_KEY_ON_NULL_COLS;
+
 			throw StandardException.newException(errorState, columnName);
 		}
 		return DataDictionary.PRIMARYKEY_CONSTRAINT;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java?rev=637244&r1=637243&r2=637244&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
Fri Mar 14 13:16:33 2008
@@ -2601,10 +2601,17 @@
 									lcc,
 									false))
 			{	
-				if (errorMsg.equals(SQLState.LANG_NULL_DATA_IN_PRIMARY_KEY))
+				if (errorMsg.equals(SQLState.LANG_NULL_DATA_IN_PRIMARY_KEY_OR_UNIQUE_CONSTRAINT))
 				{	//alter table add primary key
+					 //soft upgrade mode
 					throw StandardException.newException(
-						SQLState.LANG_NULL_DATA_IN_PRIMARY_KEY, 
+						SQLState.LANG_NULL_DATA_IN_PRIMARY_KEY_OR_UNIQUE_CONSTRAINT, 
+						td.getQualifiedName());
+				}
+				else if (errorMsg.equals(SQLState.LANG_NULL_DATA_IN_PRIMARY_KEY)) 
+				{	//alter table add primary key
+					throw StandardException.newException(
+						SQLState.LANG_NULL_DATA_IN_PRIMARY_KEY,
 						td.getQualifiedName());
 				}
 				else 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml?rev=637244&r1=637243&r2=637244&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml Fri Mar 14 13:16:33
2008
@@ -1259,6 +1259,12 @@
             </msg>
 
             <msg>
+                <name>42831.S.1</name>
+                <text>'{0}' cannot be a column of a primary key because it can contain
null values.</text>
+                <arg>columnName</arg>
+            </msg>
+
+            <msg>
                 <name>42834</name>
                 <text>SET NULL cannot be specified because FOREIGN KEY '{0}'  cannot
contain null values.  </text>
                 <arg>key</arg>
@@ -2393,6 +2399,12 @@
             </msg>
 
             <msg>
+                <name>42Z20.S.1</name>
+                <text>Column '{0}' cannot be made nullable. It is part of a primary
key, which cannot have any nullable columns.</text>
+                <arg>columnName</arg>
+            </msg>
+
+            <msg>
                 <name>42Z21</name>
                 <text>Invalid increment specified for identity for column '{0}'. Increment
cannot be zero.  </text>
                 <arg>columnName</arg>
@@ -3073,6 +3085,12 @@
             <msg>
                 <name>X0Y63.S</name>
                 <text>The command on table '{0}' failed because null data was found
in the primary key or unique constraint/index column(s). All columns in a primary or unique
index key must not be null.  </text>
+                <arg>tableName</arg>
+            </msg>
+
+            <msg>
+                <name>X0Y63.S.1</name>
+                <text>The command on table '{0}' failed because null data was found
in the primary key/index column(s). All columns in a primary key must not be null.  </text>
                 <arg>tableName</arg>
             </msg>
 

Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java?rev=637244&r1=637243&r2=637244&view=diff
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
(original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
Fri Mar 14 13:16:33 2008
@@ -771,6 +771,7 @@
 	String LANG_DB2_INVALID_COLS_SPECIFIED                             = "42802";
         String LANG_DB2_INVALID_SELECT_COL_FOR_HAVING = "42803";
 	String LANG_DB2_ADD_UNIQUE_OR_PRIMARY_KEY_ON_NULL_COLS			   = "42831";
+	String LANG_ADD_PRIMARY_KEY_ON_NULL_COLS                           = "42831.S.1";
 	String LANG_DB2_REPLACEMENT_ERROR								   = "42815.S.713";
 	String LANG_DB2_COALESCE_DATATYPE_MISMATCH								   = "42815.S.171";
 	String LANG_DB2_TOO_LONG_FLOATING_POINT_LITERAL			           = "42820";
@@ -988,6 +989,7 @@
 	String LANG_MODIFY_COLUMN_FKEY_CONSTRAINT						   = "42Z18";
 	String LANG_MODIFY_COLUMN_REFERENCED							   = "42Z19";
 	String LANG_MODIFY_COLUMN_EXISTING_CONSTRAINT					   = "42Z20";
+	String LANG_MODIFY_COLUMN_EXISTING_PRIMARY_KEY					   = "42Z20.S.1";
 
 	String LANG_AI_INVALID_INCREMENT								   = "42Z21";
 	String LANG_AI_INVALID_TYPE										   = "42Z22";
@@ -1301,7 +1303,8 @@
 	String LANG_ADDING_NON_NULL_COLUMN_TO_NON_EMPTY_TABLE              = "X0Y57.S";
 	String LANG_ADD_PRIMARY_KEY_FAILED1                                = "X0Y58.S";
 	String LANG_ADD_CHECK_CONSTRAINT_FAILED                            = "X0Y59.S";
-	String LANG_NULL_DATA_IN_PRIMARY_KEY                 	   	   	   = "X0Y63.S";
+	String LANG_NULL_DATA_IN_PRIMARY_KEY_OR_UNIQUE_CONSTRAINT      	   = "X0Y63.S";
+	String LANG_NULL_DATA_IN_PRIMARY_KEY                               = "X0Y63.S.1";
 	String LANG_NO_COMMIT_IN_NESTED_CONNECTION                         = "X0Y66.S";
 	String LANG_NO_ROLLBACK_IN_NESTED_CONNECTION                       = "X0Y67.S";
 	String LANG_OBJECT_ALREADY_EXISTS                                  = "X0Y68.S";

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/altertable.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/altertable.out?rev=637244&r1=637243&r2=637244&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/altertable.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/altertable.out
Fri Mar 14 13:16:33 2008
@@ -418,9 +418,9 @@
 alter table t0 add column c3 int;
 0 rows inserted/updated/deleted
 ij> alter table t0 add constraint cons1 primary key(c3);
-ERROR 42831: 'C3' cannot be a column of a primary key or unique key because it can contain
null values.
+ERROR 42831: 'C3' cannot be a column of a primary key because it can contain null values.
 ij> alter table t0 add primary key(c3);
-ERROR 42831: 'C3' cannot be a column of a primary key or unique key because it can contain
null values.
+ERROR 42831: 'C3' cannot be a column of a primary key because it can contain null values.
 ij> -- add constraint references non-existant column
 alter table t4 add constraint t4pk primary key("c1");
 ERROR 42X14: 'c1' is not a column in table or VTI 'T4'.
@@ -609,7 +609,7 @@
 ERROR 42X86: ALTER TABLE failed. There is no constraint 'APP.P1' on table '"APP"."T1"'. 
 ij> -- In DB2 compatibility mode, we cann't add a nullable primary key
 alter table t0_1 add constraint p2 primary key(c1);
-ERROR 42831: 'C1' cannot be a column of a primary key or unique key because it can contain
null values.
+ERROR 42831: 'C1' cannot be a column of a primary key because it can contain null values.
 ij> alter table t0_1 drop constraint p2;
 ERROR 42X86: ALTER TABLE failed. There is no constraint 'APP.P2' on table '"APP"."T0_1"'.

 ij> -- positive tests
@@ -926,13 +926,13 @@
 create table atmcn_2 (a integer not null primary key, b integer not null);
 0 rows inserted/updated/deleted
 ij> alter table atmcn_2 alter column a null;
-ERROR 42Z20: Column 'A' cannot be made nullable. It is part of a primary key or unique constraint,
which cannot have any nullable columns.
+ERROR 42Z20: Column 'A' cannot be made nullable. It is part of a primary key, which cannot
have any nullable columns.
 ij> create table atmcn_3 (a integer not null, b integer not null);
 0 rows inserted/updated/deleted
 ij> alter table atmcn_3 add constraint atmcn_3_pk primary key(a, b);
 0 rows inserted/updated/deleted
 ij> alter table atmcn_3 alter column b null;
-ERROR 42Z20: Column 'B' cannot be made nullable. It is part of a primary key or unique constraint,
which cannot have any nullable columns.
+ERROR 42Z20: Column 'B' cannot be made nullable. It is part of a primary key, which cannot
have any nullable columns.
 ij> -- verify that the keyword "column" in the ALTER TABLE ... ALTER COLUMN ...
 -- statement is optional:
 create table atmcn_4 (a integer not null, b integer);

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/db2Compatibility.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/db2Compatibility.out?rev=637244&r1=637243&r2=637244&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/db2Compatibility.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/db2Compatibility.out
Fri Mar 14 13:16:33 2008
@@ -1704,7 +1704,7 @@
 create table t1 (c1 int, c2 int);
 0 rows inserted/updated/deleted
 ij> alter table t1 add constraint pk1 primary key (c1);
-ERROR 42831: 'C1' cannot be a column of a primary key or unique key because it can contain
null values.
+ERROR 42831: 'C1' cannot be a column of a primary key because it can contain null values.
 ij> alter table t1 add constraint uc1 unique (c2);
 0 rows inserted/updated/deleted
 ij> -- positive tests

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/nulls.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/nulls.out?rev=637244&r1=637243&r2=637244&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/nulls.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/nulls.out
Fri Mar 14 13:16:33 2008
@@ -61,7 +61,7 @@
 ij> insert into a values(1, NULL);
 1 row inserted/updated/deleted
 ij> alter table a add constraint ap1 primary key(a1, a2);
-ERROR 42831: 'A2' cannot be a column of a primary key or unique key because it can contain
null values.
+ERROR 42831: 'A2' cannot be a column of a primary key because it can contain null values.
 ij> drop table a;
 0 rows inserted/updated/deleted
 ij> -- try with multiple columns
@@ -69,7 +69,7 @@
 0 rows inserted/updated/deleted
 ij> -- This is an error in DB2 compatibility mode
 alter table a add constraint ap1 primary key(a1, a2, a3);
-ERROR 42831: 'A1' cannot be a column of a primary key or unique key because it can contain
null values.
+ERROR 42831: 'A1' cannot be a column of a primary key because it can contain null values.
 ij> drop table a;
 0 rows inserted/updated/deleted
 ij> -- try with multiple null columns
@@ -79,7 +79,7 @@
 1 row inserted/updated/deleted
 ij> -- table with no null data should work
 alter table a add constraint ap1 primary key(a1, a2, a3);
-ERROR 42831: 'A2' cannot be a column of a primary key or unique key because it can contain
null values.
+ERROR 42831: 'A2' cannot be a column of a primary key because it can contain null values.
 ij> -- insert a null into one of the primary key columns should fail
 insert into a values(1, NULL, 1);
 1 row inserted/updated/deleted
@@ -92,7 +92,7 @@
 1 row inserted/updated/deleted
 ij> -- table with some null data should fail
 alter table a add constraint ap1 primary key(a1, a2, a3);
-ERROR 42831: 'A2' cannot be a column of a primary key or unique key because it can contain
null values.
+ERROR 42831: 'A2' cannot be a column of a primary key because it can contain null values.
 ij> -- defining primarykey column constraint for explicitly nullable column
 -- gives error
 create table a1(ac1 int null primary key);



Mime
View raw message