db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject svn commit: r1068438 - in /db/derby/code/branches/10.6: ./ java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsPermsTest.java
Date Tue, 08 Feb 2011 15:18:22 GMT
Author: mikem
Date: Tue Feb  8 15:18:22 2011
New Revision: 1068438

URL: http://svn.apache.org/viewvc?rev=1068438&view=rev
Log:
DERBY-3944: Always compile CHECK constraints in the schema of the target table. 

backported change #964402 from trunk to 10.6 branch.


Modified:
    db/derby/code/branches/10.6/   (props changed)
    db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java
    db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsPermsTest.java

Propchange: db/derby/code/branches/10.6/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Feb  8 15:18:22 2011
@@ -1,2 +1,2 @@
-/db/derby/code/trunk:938547,938796,938959,939231,940462,940469,941627,942031,942286,942476,942480,942587,944152,946794,948045,948069,951346,951366,952138,952237,952581,954344,954421,954544,954748,955001,955540,955634,956075,956234,956445,956569,956659,957260,957902,958163,958257,958264,958508,958522,958555,958618,958939,959550,961892,962716,963206,963705,964115,965647,967304,980684,986689,986834,987539,989099,990292,997325,998170,999119,1002291,1002682,1002853,1021426,1025795,1028716,1030043,1033864,1038514,1040658,1053724,1055169,1062096,1063809,1065061,1067250
+/db/derby/code/trunk:938547,938796,938959,939231,940462,940469,941627,942031,942286,942476,942480,942587,944152,946794,948045,948069,951346,951366,952138,952237,952581,954344,954421,954544,954748,955001,955540,955634,956075,956234,956445,956569,956659,957260,957902,958163,958257,958264,958508,958522,958555,958618,958939,959550,961892,962716,963206,963705,964115,964402,965647,967304,980684,986689,986834,987539,989099,990292,997325,998170,999119,1002291,1002682,1002853,1021426,1025795,1028716,1030043,1033864,1038514,1040658,1053724,1055169,1062096,1063809,1065061,1067250
 /db/derby/docs/trunk:954344

Modified: db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java?rev=1068438&r1=1068437&r2=1068438&view=diff
==============================================================================
--- db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java
(original)
+++ db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java
Tue Feb  8 15:18:22 2011
@@ -627,8 +627,10 @@ abstract class DMLModStatementNode exten
 			return null;
 		}
 
+        CompilerContext compilerContext = getCompilerContext();
+        
  		// Donot need privileges to execute constraints
-		getCompilerContext().pushCurrentPrivType( Authorizer.NULL_PRIV);
+		compilerContext.pushCurrentPrivType( Authorizer.NULL_PRIV);
 		try {
 			getAllRelevantConstraints(dataDictionary, 	
 											targetTableDescriptor, 
@@ -652,15 +654,24 @@ abstract class DMLModStatementNode exten
 
             if (checkConstraints != null)
 			{
-				bindRowScopedExpression(nodeFactory, getContextManager(),
-								targetTableDescriptor,
-								sourceRCL,
-								checkConstraints);
+                SchemaDescriptor    originalCurrentSchema = targetTableDescriptor.getSchemaDescriptor();
+                compilerContext.pushCompilationSchema( originalCurrentSchema );
+
+                try {
+                    bindRowScopedExpression(nodeFactory, getContextManager(),
+                                            targetTableDescriptor,
+                                            sourceRCL,
+                                            checkConstraints);
+                }
+                finally
+                {
+                    compilerContext.popCompilationSchema();
+                }
 			}
 		}
 		finally
 		{
-			getCompilerContext().popCurrentPrivType();
+			compilerContext.popCurrentPrivType();
 		}
 
 		return	checkConstraints;

Modified: db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsPermsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsPermsTest.java?rev=1068438&r1=1068437&r2=1068438&view=diff
==============================================================================
--- db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsPermsTest.java
(original)
+++ db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsPermsTest.java
Tue Feb  8 15:18:22 2011
@@ -637,6 +637,152 @@ public class GeneratedColumnsPermsTest e
 
     }
     
+    /**
+     * <p>
+     * Test that unqualified function references in check constraints resolve
+     * to the current schema in effect when the constraint was declared.
+     * See DERBY-3944, which is related to the bug above, DERBY-3945.
+     * </p>
+     */
+    public  void    test_005_functionSchema()
+        throws Exception
+    {
+        Connection  dboConnection = openUserConnection( TEST_DBO );
+        Connection  janetConnection = openUserConnection( JANET );
+
+        goodStatement
+            (
+             dboConnection,
+             "create function f_3944\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_3944( a int, constraint t_3944_check check ( f_3944( a ) <
0 ) )"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "grant insert on t_3944 to public"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "grant execute on function f_3944 to public"
+             );
+
+        expectExecutionError
+            (
+             janetConnection,
+             CONSTRAINT_VIOLATION,
+             "insert into test_dbo.t_3944( a ) values ( -100 )"
+             );
+        goodStatement
+            (
+             janetConnection,
+             "insert into test_dbo.t_3944( a ) values ( 200 )"
+             );
+        assertResults
+            (
+             dboConnection,
+             "select * from t_3944 order by a",
+             new String[][]
+             {
+                 { "200", },
+             },
+             false
+             );
+    }
+
+   /**
+     * <p>
+     * Test that unqualified function references in views resolve
+     * to the view's schema.
+     * See DERBY-3953, which is related to the bugs above, DERBY-3944 and DERBY-3945.
+     * </p>
+     */
+    public  void    test_006_functionSchema()
+        throws Exception
+    {
+        Connection  dboConnection = openUserConnection( TEST_DBO );
+        Connection  janetConnection = openUserConnection( JANET );
+
+        goodStatement
+            (
+             dboConnection,
+             "create function f_3953\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 view v_3953( a, b ) as values ( f_3953( 1 ), f_3953( 2 ) )"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "grant select on v_3953 to public"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "grant execute on function f_3953 to public"
+             );
+        
+        goodStatement
+            (
+             janetConnection,
+             "create function f_3953\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"
+             );
+        
+        assertResults
+            (
+             janetConnection,
+             "values ( f_3953( 1 ), f_3953( 2 ) )",
+             new String[][]
+             {
+                 { "1", "2" },
+             },
+             false
+             );
+        assertResults
+            (
+             janetConnection,
+             "select * from test_dbo.v_3953",
+             new String[][]
+             {
+                 { "-1", "-2" },
+             },
+             false
+             );
+    }
+
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // MINIONS



Mime
View raw message