db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r719123 - in /db/derby/code/trunk/java: engine/org/apache/derby/catalog/ engine/org/apache/derby/catalog/types/ engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Wed, 19 Nov 2008 23:14:35 GMT
Author: rhillegas
Date: Wed Nov 19 15:14:34 2008
New Revision: 719123

URL: http://svn.apache.org/viewvc?rev=719123&view=rev
Log:
DERBY-3945: Resolve unqualified function names in generation clauses against the current schema
from DDL rather than DML time.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/DefaultInfo.java
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/DefaultInfoImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsPermsTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/DefaultInfo.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/DefaultInfo.java?rev=719123&r1=719122&r2=719123&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/DefaultInfo.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/DefaultInfo.java Wed Nov 19 15:14:34
2008
@@ -58,5 +58,11 @@
 	 */
 	public boolean isGeneratedColumn();
 	
+	/**
+	 * Return the name of the current schema when the default was created. This
+	 * is filled in for generated columns.
+	 */
+	public String   getOriginalCurrentSchema();
+	
 
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/DefaultInfoImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/DefaultInfoImpl.java?rev=719123&r1=719122&r2=719123&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/DefaultInfoImpl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/DefaultInfoImpl.java Wed
Nov 19 15:14:34 2008
@@ -56,6 +56,7 @@
 	private String				defaultText;
 	private int                     type;
     private String[]                   referencedColumnNames;
+    private String                  originalCurrentSchema;
 
 	final private static int BITS_MASK_IS_DEFAULTVALUE_AUTOINC = 0x1 << 0;
 	final private static int BITS_MASK_IS_GENERATED_COLUMN = 0x2;
@@ -86,7 +87,8 @@
 	public DefaultInfoImpl
         (
          String defaultText,
-         String[]    referencedColumnNames
+         String[]    referencedColumnNames,
+         String originalCurrentSchema
          )
 	{
         if ( referencedColumnNames == null ) { referencedColumnNames = new String[0]; }
@@ -94,6 +96,7 @@
 		this.type = BITS_MASK_IS_GENERATED_COLUMN;
 		this.defaultText = defaultText;
 		this.referencedColumnNames = referencedColumnNames;
+        this.originalCurrentSchema = originalCurrentSchema;
 	}
 
 	/**
@@ -112,6 +115,14 @@
 		return referencedColumnNames;
 	}
 
+	/**
+	 * @see DefaultInfo#getOriginalCurrentSchema
+	 */
+	public String   getOriginalCurrentSchema()
+	{
+		return originalCurrentSchema;
+	}
+
 	public String	toString()
 	{
 		if(isDefaultValueAutoinc()){
@@ -146,6 +157,7 @@
             int count = in.readInt();
             referencedColumnNames = new String[ count ];
             for ( int i = 0; i < count; i++ ) { referencedColumnNames[ i ] = (String)
in.readObject(); }
+            originalCurrentSchema = (String) in.readObject();
         }
 	}
 
@@ -168,6 +180,7 @@
             int count = referencedColumnNames.length;
             out.writeInt( count );
             for ( int i = 0; i < count; i++ ) { out.writeObject( referencedColumnNames[
i ] ); }
+            out.writeObject( originalCurrentSchema );
         }
 	}
  

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java?rev=719123&r1=719122&r2=719123&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java
Wed Nov 19 15:14:34 2008
@@ -27,6 +27,7 @@
 import java.util.HashSet;
 import java.util.Vector;
 
+import org.apache.derby.catalog.DefaultInfo;
 import org.apache.derby.catalog.UUID;
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.reference.ClassName;
@@ -496,6 +497,7 @@
     )
 		throws StandardException
 	{
+		CompilerContext 			compilerContext = getCompilerContext();
         int  count = targetRCL.size();
 
         for ( int i = 0; i < count; i++ )
@@ -514,7 +516,8 @@
             {
                 ColumnDescriptor    colDesc = rc.getTableColumnDescriptor();
                 DataTypeDescriptor  dtd = colDesc.getType();
-                ValueNode   generationClause = parseGenerationClause( colDesc.getDefaultInfo().getDefaultText(),
targetTableDescriptor );
+                DefaultInfo             di = colDesc.getDefaultInfo();
+                ValueNode   generationClause = parseGenerationClause( di.getDefaultText(),
targetTableDescriptor );
 
                 // insert CAST in case column data type is not same as the
                 // resolved type of the generation clause
@@ -526,7 +529,20 @@
                      getContextManager()
                      );
 
-                bindRowScopedExpression( getNodeFactory(), getContextManager(), targetTableDescriptor,
sourceRCL, generationClause );
+                //
+                // Unqualified function references should resolve to the
+                // current schema at the time that the table was
+                // created/altered. See DERBY-3945.
+                //
+                SchemaDescriptor    originalCurrentSchema = getSchemaDescriptor( di.getOriginalCurrentSchema(),
true );
+                SchemaDescriptor    previousSchema = compilerContext.setCompilationSchema(
originalCurrentSchema );
+                try {
+                    bindRowScopedExpression( getNodeFactory(), getContextManager(), targetTableDescriptor,
sourceRCL, generationClause );
+                }
+                finally
+                {
+                    compilerContext.setCompilationSchema( previousSchema );
+                }
 
                 ResultColumn    newRC =  (ResultColumn) getNodeFactory().getNode
                     ( C_NodeTypes.RESULT_COLUMN, generationClause.getTypeServices(), generationClause,
getContextManager());

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=719123&r1=719122&r2=719123&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
Wed Nov 19 15:14:34 2008
@@ -847,8 +847,9 @@
                 referencedColumnNames[ i ] = ((ResultColumn)rcl.elementAt( generationClauseColumnReferences[
i ] - 1 )).getName();
             }
 
+            String              currentSchemaName = getLanguageConnectionContext().getCurrentSchemaName();
             DefaultInfoImpl dii = new DefaultInfoImpl
-                ( generationClauseNode.getExpressionText(), referencedColumnNames );
+                ( generationClauseNode.getExpressionText(), referencedColumnNames, currentSchemaName
);
             cdn.setDefaultInfo( dii );
 
 			/* Clear the column references in the RCL so each generation clause

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsPermsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsPermsTest.java?rev=719123&r1=719122&r2=719123&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsPermsTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsPermsTest.java
Wed Nov 19 15:14:34 2008
@@ -453,6 +453,190 @@
              );
     }
     
+    /**
+     * <p>
+     * Test that unqualified function references in generation clauses resolve
+     * to the current schema in effect when the generated column was added.
+     * See DERBY-3945.
+     * </p>
+     */
+    public  void    test_004_functionSchema()
+        throws Exception
+    {
+        Connection  dboConnection = openUserConnection( TEST_DBO );
+        Connection  janetConnection = openUserConnection( JANET );
+
+        //
+        // Schema.
+        //
+        goodStatement
+            (
+             dboConnection,
+             "create function f_fsch_1\n" +
+             "(\n" +
+             "    a int\n" +
+             ")\n" +
+             "returns int\n" +
+             "language java\n" +
+             "deterministic\n" +
+             "parameter style java\n" +
+             "no sql\n" +
+             "external name 'org.apache.derbyTesting.functionTests.tests.lang.GeneratedColumnsTest.minus'\n"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "create table t_fsch_1( a int, b generated always as ( f_fsch_1( a ) ) )"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "create table t_fsch_2( a int )"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "alter table t_fsch_2 add column b generated always as ( f_fsch_1( a ) )"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "grant execute on function f_fsch_1 to public"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "grant select on t_fsch_1 to public"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "grant insert on t_fsch_1 to public"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "grant update on t_fsch_1 to public"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "grant select on t_fsch_2 to public"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "grant insert on t_fsch_2 to public"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "grant update on t_fsch_2 to public"
+             );
+
+        goodStatement
+            (
+             janetConnection,
+             "create function f_fsch_1\n" +
+             "(\n" +
+             "    a int\n" +
+             ")\n" +
+             "returns int\n" +
+             "language java\n" +
+             "deterministic\n" +
+             "parameter style java\n" +
+             "no sql\n" +
+             "external name 'java.lang.Math.abs'\n"
+             );
+
+        //
+        // Populate
+        //
+        goodStatement
+            (
+             dboConnection,
+             "insert into test_dbo.t_fsch_1( a ) values ( 1 )"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "insert into test_dbo.t_fsch_2( a ) values ( 2 )"
+             );
+
+        //
+        // Verify insert by other user
+        //
+        goodStatement
+            (
+             janetConnection,
+             "insert into test_dbo.t_fsch_1( a ) values ( 1 )"
+             );
+        assertResults
+            (
+             janetConnection,
+             "select * from test_dbo.t_fsch_1 order by a",
+             new String[][]
+             {
+                 { "1", "-1", },
+                 { "1", "-1", },
+             },
+             false
+             );
+        goodStatement
+            (
+             janetConnection,
+             "insert into test_dbo.t_fsch_2( a ) values ( 2 )"
+             );
+        assertResults
+            (
+             janetConnection,
+             "select * from test_dbo.t_fsch_2 order by a",
+             new String[][]
+             {
+                 { "2", "-2", },
+                 { "2", "-2", },
+             },
+             false
+             );
+
+        //
+        // Verify update by other user
+        //
+        goodStatement
+            (
+             janetConnection,
+             "update test_dbo.t_fsch_1 set a = 100 + a"
+             );
+        assertResults
+            (
+             janetConnection,
+             "select * from test_dbo.t_fsch_1 order by a",
+             new String[][]
+             {
+                 { "101", "-101", },
+                 { "101", "-101", },
+             },
+             false
+             );
+        goodStatement
+            (
+             janetConnection,
+             "update test_dbo.t_fsch_2 set a = 100 + a"
+             );
+        assertResults
+            (
+             janetConnection,
+             "select * from test_dbo.t_fsch_2 order by a",
+             new String[][]
+             {
+                 { "102", "-102", },
+                 { "102", "-102", },
+             },
+             false
+             );
+
+    }
+    
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // MINIONS



Mime
View raw message