db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1360736 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/FromVTI.java testing/org/apache/derbyTesting/functionTests/tests/lang/TableFunctionTest.java
Date Thu, 12 Jul 2012 15:53:36 GMT
Author: rhillegas
Date: Thu Jul 12 15:53:35 2012
New Revision: 1360736

URL: http://svn.apache.org/viewvc?rev=1360736&view=rev
Log:
DERBY-5779: Forbid joining to VTI/tableFunction args in <joined table> clauses.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TableFunctionTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java?rev=1360736&r1=1360735&r2=1360736&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java Thu Jul
12 15:53:35 2012
@@ -885,27 +885,40 @@ public class FromVTI extends FromTable i
             //
             // Table Function parameters may not reference columns from other tables in the
             // FROM list of the current query block. See DERBY-5579. We also do not allow
-            // VTI parameters to refer to other VTIs.
+            // VTI parameters to refer to other VTIs. We also do not allow even VTIs to
+            // reference other elements in the current <joined table>.
             //
             int referencedTableNumber = ref.getTableNumber();
+            boolean illegalReference = !ref.getCorrelated();
 
-            for ( int i = 0; i < fromListParam.size(); i++ )
+            if ( !ref.getCorrelated() ) // if the arg refers to a table in this query block
             {
-                FromTable   fromTable = (FromTable) fromListParam.elementAt( i );
-
-                if ( referencedTableNumber == fromTable.getTableNumber() )
+                for ( int i = 0; i < fromListParam.size(); i++ )
                 {
-                    // remember this FromTable so that we can code generate the arg
-                    // from actual result columns later on.
-                    argSources.put( new Integer( fromTable.getTableNumber() ), fromTable
);
-                    
-                    if ( isDerbyStyleTableFunction || (fromTable instanceof FromVTI) )
+                    FromTable   fromTable = (FromTable) fromListParam.elementAt( i );
+
+                    if ( referencedTableNumber == fromTable.getTableNumber() )
                     {
-                        throw StandardException.newException
-                            ( SQLState.LANG_BAD_TABLE_FUNCTION_PARAM_REF, ref.getSQLColumnName()
);
+                        // remember this FromTable so that we can code generate the arg
+                        // from actual result columns later on.
+                        argSources.put( new Integer( fromTable.getTableNumber() ), fromTable
);
+
+                        // the only legal kind of reference is a VTI argument which
+                        // references a non-VTI table in the current query block
+                        if ( !isDerbyStyleTableFunction && !(fromTable instanceof
FromVTI) )
+                        {
+                            illegalReference = false;
+                            break;
+                        }
                     }
                 }
             }
+            
+            if ( illegalReference )
+            {
+                throw StandardException.newException
+                    ( SQLState.LANG_BAD_TABLE_FUNCTION_PARAM_REF, ref.getSQLColumnName()
);
+            }
 
 			// Rebind the CR if the tableNumber is uninitialized
 			if (ref.getTableNumber() == -1)

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TableFunctionTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TableFunctionTest.java?rev=1360736&r1=1360735&r2=1360736&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TableFunctionTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TableFunctionTest.java
Thu Jul 12 15:53:35 2012
@@ -52,6 +52,8 @@ public class TableFunctionTest extends B
 
     private static  final   String  UTF8 = "UTF-8";
 
+    private static  final   String  BAD_ARG_JOIN = "42ZB7";
+
     private static  final   int MAX_VARIABLE_DATA_TYPE_LENGTH = 32700;
     
     // functions to drop at teardown time
@@ -2064,10 +2066,34 @@ public class TableFunctionTest extends B
         // by DERBY-5779.
         expectError
             (
-             "42ZB7",
+             BAD_ARG_JOIN,
              "select tablename, contents\n" +
              "from sys.systables t, table( lowerCaseRow( cast (t.tablename as varchar(32672))
) ) s\n"
              );
+        // diagnostic vti arg joining to another table in a <joined table> clause
+        expectError
+            (
+             BAD_ARG_JOIN,
+             "select tt.* from table(syscs_diag.space_table(st.tablename)) tt join sys.systables
st using(tableid)"
+             );
+        // table function arg joining to another table in a <joined table> clause
+        expectError
+            (
+             BAD_ARG_JOIN,
+             "select tt.* from table( lowerCaseRow(st.tablename)) tt join sys.systables st
on tt.contents = st.tablename"
+             );
+        // diagnostic vti arg joining to another table in a <joined table> clause
+        expectError
+            (
+             BAD_ARG_JOIN,
+             "select tt.* from table(syscs_diag.space_table(st.tablename)) tt right join
sys.systables st using(tableid)"
+             );
+        // table function arg joining to another table in a <joined table> clause
+        expectError
+            (
+             BAD_ARG_JOIN,
+             "select tt.* from table( lowerCaseRow(st.tablename)) tt right join sys.systables
st on tt.contents = st.tablename"
+             );
 
         // pre-existing error not affected: table function correlated
         // to inner query block



Mime
View raw message