db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r712664 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ engine/org/apache/derby/loc/ shared/org/apache/derby/shared/common/reference/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Mon, 10 Nov 2008 14:29:03 GMT
Author: rhillegas
Date: Mon Nov 10 06:29:03 2008
New Revision: 712664

URL: http://svn.apache.org/viewvc?rev=712664&view=rev
Log:
DERBY-481: Forbid renaming of columns referenced by generation clauses and prevent users from
adding defaults to generated columns.

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/RenameNode.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/tests/lang/GeneratedColumnsTest.java

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=712664&r1=712663&r2=712664&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
Mon Nov 10 06:29:03 2008
@@ -344,7 +344,14 @@
 		// aspects of the autoincrement settings that it intends to change,
 		// and does not lose the other aspecs.
 		if (defaultNode == null)
-			defaultInfo = (DefaultInfoImpl)cd.getDefaultInfo();
+        { defaultInfo = (DefaultInfoImpl)cd.getDefaultInfo(); }
+        else
+        {
+            if ( cd.hasGenerationClause() )
+            {
+				throw StandardException.newException( SQLState.LANG_GEN_COL_DEFAULT, cd.getColumnName()
);
+            }
+        }
 		if (autoinc_create_or_modify_Start_Increment ==
 				ColumnDefinitionNode.MODIFY_AUTOINCREMENT_RESTART_VALUE)
 			autoincrementIncrement = cd.getAutoincInc();

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/RenameNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/RenameNode.java?rev=712664&r1=712663&r2=712664&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/RenameNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/RenameNode.java Mon
Nov 10 06:29:03 2008
@@ -372,6 +372,27 @@
   		if (cd != null)
   			throw descriptorExistsException(cd, td);
 
+        //
+		// You cannot rename a column which is referenced by the generation
+        // clause of a generated column.
+        //
+        ColumnDescriptorList    generatedColumns = td.getGeneratedColumns();
+        int                                 generatedColumnCount = generatedColumns.size();
+        for ( int i = 0; i < generatedColumnCount; i++ )
+        {
+            ColumnDescriptor    gc = generatedColumns.elementAt( i );
+            String[]                    referencedColumns = gc.getDefaultInfo().getReferencedColumnNames();
+            int                         refColCount = referencedColumns.length;
+            for ( int j = 0; j < refColCount; j++ )
+            {
+                String      refName = referencedColumns[ j ];
+                if ( oldObjectName.equals( refName ) )
+                {
+                    throw StandardException.newException( SQLState.LANG_GEN_COL_BAD_RENAME,
oldObjectName, gc.getColumnName() );
+                }
+            }
+        }
+
 		/* Verify that there are no check constraints using the column being renamed */
 		ConstraintDescriptorList constraintDescriptorList =
 			dd.getConstraintDescriptors(td);

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=712664&r1=712663&r2=712664&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 Mon Nov 10 06:29:03
2008
@@ -2008,7 +2008,13 @@
 
             <msg>
                 <name>42XA7</name>
-                <text>Dropping column '{0}' would orphan the generated column '{1}'
which references it. You must drop the generated column first.</text>
+                <text>'{0}' is a generated column. You cannot change its default value.</text>
+                <arg>columnName</arg>
+            </msg>
+
+            <msg>
+                <name>42XA8</name>
+                <text>You cannot rename '{0}' because it is referenced by the generation
clause of column '{1}'.</text>
                 <arg>columnName</arg>
                 <arg>columnName</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=712664&r1=712663&r2=712664&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
Mon Nov 10 06:29:03 2008
@@ -901,7 +901,8 @@
     String LANG_CANT_REFERENCE_GENERATED_COLUMN                  = "42XA4";
     String LANG_ROUTINE_CANT_PERMIT_SQL                                   = "42XA5";
     String LANG_BAD_FK_ON_GENERATED_COLUMN                           = "42XA6";
-    String LANG_CASCADED_GEN_COL_DROP                                     = "42XA7";
+    String LANG_GEN_COL_DEFAULT                                                 = "42XA7";
+    String LANG_GEN_COL_BAD_RENAME                                           = "42XA8";
 	String LANG_INVALID_USER_AGGREGATE_DEFINITION2                     = "42Y00";
 	String LANG_INVALID_CHECK_CONSTRAINT                               = "42Y01";
 	// String LANG_NO_ALTER_TABLE_COMPRESS_ON_TARGET_TABLE                = "42Y02";

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=712664&r1=712663&r2=712664&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
Mon Nov 10 06:29:03 2008
@@ -63,6 +63,8 @@
     private static  final   String  CANT_REFERENCE_GENERATED_COLUMN = "42XA4";
     private static  final   String  ROUTINE_CANT_ISSUE_SQL = "42XA5";
     private static  final   String  BAD_FOREIGN_KEY_ACTION = "42XA6";
+    private static  final   String  ILLEGAL_ADD_DEFAULT = "42XA7";
+    private static  final   String  ILLEGAL_RENAME = "42XA8";
     private static  final   String  NOT_NULL_VIOLATION = "23502";
     private static  final   String  CONSTRAINT_VIOLATION = "23513";
     private static  final   String  FOREIGN_KEY_VIOLATION = "23503";
@@ -3188,6 +3190,41 @@
              );
     }
     
+    /**
+     * <p>
+     * Test ALTER TABLE ALTER COLUMN
+     * </p>
+     */
+    public  void    test_020_alterColumn()
+        throws Exception
+    {
+        Connection  conn = getConnection();
+
+        //
+        // Verify that you can't add a default to a generated column.
+        //        
+        goodStatement
+            (
+             conn,
+             "create table t_ad_1( a int generated always as ( -b ), b int, c int )"
+             );
+        expectCompilationError
+            (
+             ILLEGAL_ADD_DEFAULT,
+             "alter table t_ad_1 alter column a with default 1"
+             );
+        
+        //
+        // Verify that you can't rename a column which is mentioned by a
+        // generation clause.
+        //        
+        expectCompilationError
+            (
+             ILLEGAL_RENAME,
+             "rename column t_ad_1.b to d"
+             );
+    }
+
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // MINIONS
@@ -3474,11 +3511,12 @@
     //
     ///////////////////////////////////////////////////////////////////////////////////
 
-    public static   int minus( int a )
+    public static   Integer minus( Integer a )
     {
         _minusCounter++;
 
-        return -a;
+        if ( a == null ) { return null; }
+        else { return new Integer( -a.intValue() ); }
     }
     
     public static   int readMinusCounter()



Mime
View raw message