db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject svn commit: r1068572 - in /db/derby/code/branches/10.5: ./ 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 20:48:00 GMT
Author: mikem
Date: Tue Feb  8 20:48:00 2011
New Revision: 1068572

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

backported change #964402 from trunk to 10.5 branch. 


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

Propchange: db/derby/code/branches/10.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Feb  8 20:48:00 2011
@@ -1,2 +1,2 @@
 /db/derby/code/branches/10.6:942027,957000,962738,965351,987678,997790*,1031623,1055601
-/db/derby/code/trunk:757811,764912,769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,791027,792001,792254,792434,793089,793588,794106,794276,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,827505,829022,829410,830545,831304,831319,832379,833430,835286,881074,881444,882732,884163,885421,885659,887246,888311,891350,892912,897161,898635,901165,901648,901760,902857,903108,905224,908418,908586,909176,910481,910511,911315,911793,915177,915733,916075,916897,917771,918152,918359,921028,927430,928065,929085,931076,934474,936215,938959,940462,940469,942286,942476,942480,942587,946794,948045,948069,951346,951366,952138,952581,954748,955001,955634,956075,956445,956659,958163,959550,961892,962716,965647,967304,980684,986689,986834,987539,989099,99
 7325*,999119,1002291,1002682,1002853,1021426,1025795,1030043,1040658,1053724,1055169,1062096,1063809,1065061,1067250
+/db/derby/code/trunk:757811,764912,769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,791027,792001,792254,792434,793089,793588,794106,794276,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,827505,829022,829410,830545,831304,831319,832379,833430,835286,881074,881444,882732,884163,885421,885659,887246,888311,891350,892912,897161,898635,901165,901648,901760,902857,903108,905224,908418,908586,909176,910481,910511,911315,911793,915177,915733,916075,916897,917771,918152,918359,921028,927430,928065,929085,931076,934474,936215,938959,940462,940469,942286,942476,942480,942587,946794,948045,948069,951346,951366,952138,952581,954748,955001,955634,956075,956445,956659,958163,959550,961892,962716,964402,965647,967304,980684,986689,986834,987539,98
 9099,997325*,999119,1002291,1002682,1002853,1021426,1025795,1030043,1040658,1053724,1055169,1062096,1063809,1065061,1067250

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java?rev=1068572&r1=1068571&r2=1068572&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java
(original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java
Tue Feb  8 20:48:00 2011
@@ -625,8 +625,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, 
@@ -650,15 +652,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.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsPermsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsPermsTest.java?rev=1068572&r1=1068571&r2=1068572&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsPermsTest.java
(original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsPermsTest.java
Tue Feb  8 20:48:00 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