You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by da...@apache.org on 2009/08/27 18:34:53 UTC

svn commit: r808504 - in /db/derby/code/branches/10.5: ./ java/engine/org/apache/derby/impl/sql/compile/FromBaseTable.java java/testing/org/apache/derbyTesting/functionTests/tests/lang/ViewsTest.java

Author: dag
Date: Thu Aug 27 16:34:48 2009
New Revision: 808504

URL: http://svn.apache.org/viewvc?rev=808504&view=rev
Log:
DERBY-3478 Simple column names specified as part of "AS" clause in a table expression are ignored if the table expression is a view.

Patch DERBY-3478 fixes this issue and adds a new test case.

The fix adds a call to propagateDCLInfo also for views in
FromBaseTable.bindNonVTITables which seems to have been always
missing.

Backported from trunk as:

svn merge -c 808494 https://svn.eu.apache.org/repos/asf/db/derby/code/trunk

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

Propchange: db/derby/code/branches/10.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Aug 27 16:34:48 2009
@@ -1 +1 @@
-/db/derby/code/trunk:769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,792434,793089,793588,794106,794303,794955,795166,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696
+/db/derby/code/trunk:769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,792434,793089,793588,794106,794303,794955,795166,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/FromBaseTable.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/FromBaseTable.java?rev=808504&r1=808503&r2=808504&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/FromBaseTable.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/FromBaseTable.java Thu Aug 27 16:34:48 2009
@@ -2291,8 +2291,19 @@
 				// since we reset the compilation schema when we return, we
 				// need to save it for use when we bind expressions:
 				fsq.setOrigCompilationSchema(compSchema);
+				ResultSetNode fsqBound =
+					fsq.bindNonVTITables(dataDictionary, fromListParam);
 
-				return fsq.bindNonVTITables(dataDictionary, fromListParam);
+				/* Do error checking on derived column list and update "exposed"
+				 * column names if valid.
+				 */
+				if (derivedRCL != null) {
+					fsqBound.getResultColumns().propagateDCLInfo(
+						derivedRCL,
+						origTableName.getFullTableName());
+				}
+
+				return fsqBound;
 			}
 			finally
 			{

Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ViewsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ViewsTest.java?rev=808504&r1=808503&r2=808504&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ViewsTest.java (original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ViewsTest.java Thu Aug 27 16:34:48 2009
@@ -824,4 +824,86 @@
         s.executeUpdate("DROP VIEW V");
         s.executeUpdate("DROP TABLE A");        
     }
+
+
+    /**
+     * DERBY-3478
+     * Make sure column names are correct when we select from a view and also
+     * give a table correation name with derived column list.
+     *
+     * E.g. SELECT * FROM V1 X(A,B)
+     *
+     * @throws SQLException
+     */
+    public void testViewMetaDataWithCorrelationNameAndDerivedColumnList_3478()
+            throws SQLException
+    {
+        Statement s = createStatement();
+        s.executeUpdate("create table t1 (i int, j int)");
+        s.executeUpdate("insert into t1 values (1, 1), (1, -1), " +
+                        "                      (2, 2), (3, -3), (4, 4)");
+
+        s.executeUpdate("create view v1 as select j, i from t1");
+        s.executeUpdate("create view v2 (x,y,z) as select j, i, i+j from t1");
+
+        DatabaseMetaData dmd = getConnection().getMetaData();
+        ResultSet columns = dmd.getColumns(null, null, "V1", null);
+
+        String[][] expectedDBMetaRows = new String[][]
+            {{"","APP","V1","J","4","INTEGER","10",null,"0","10","1","",
+              null,null,null,null,"1","YES",null,null,null,null,"NO"},
+             {"","APP","V1","I","4","INTEGER","10",null,"0","10","1","",
+              null,null,null,null,"2","YES",null,null,null,null,"NO"}};
+
+        JDBC.assertFullResultSet(columns,expectedDBMetaRows);
+
+        expectedDBMetaRows = new String[][]
+            {{"","APP","V2","X","4","INTEGER","10",null,"0","10","1","",
+              null,null,null,null,"1","YES",null,null,null,null,"NO"},
+             {"","APP","V2","Y","4","INTEGER","10",null,"0","10","1","",
+              null,null,null,null,"2","YES",null,null,null,null,"NO"},
+             {"","APP","V2","Z","4","INTEGER","10",null,"0","10","1","",
+              null,null,null,null,"3","YES",null,null,null,null,"NO"}};
+
+        columns = dmd.getColumns(null, null, "V2", null);
+        JDBC.assertFullResultSet(columns,expectedDBMetaRows);
+
+        // Make sure ResultSetMetaData is right when selecting from view. This
+        // exposes DERBY-3478 if not fixed.
+
+        ResultSet rs = s.executeQuery("select * from v1 x(a,b)");
+        JDBC.assertColumnNames(rs, new String[] {"A","B"});
+        JDBC.assertColumnTypes(rs, new int[] {java.sql.Types.INTEGER,
+                                              java.sql.Types.INTEGER});
+        JDBC.assertNullability(rs,new boolean[] {true,true});
+
+        // Check the results.
+        String [][] expectedRows = new String[][]
+            {{"1","1"},
+             {"-1","1"},
+             {"2","2"},
+             {"-3","3"},
+             {"4","4"}};
+        JDBC.assertFullResultSet(rs, expectedRows);
+
+        rs = s.executeQuery("select * from v2 as x(a,b,d)");
+        JDBC.assertColumnNames(rs, new String[] {"A","B","D"});
+        JDBC.assertColumnTypes(rs, new int[] {java.sql.Types.INTEGER,
+                                              java.sql.Types.INTEGER,
+                                              java.sql.Types.INTEGER});
+        JDBC.assertNullability(rs,new boolean[] {true,true, true});
+
+        // Check the results.
+        expectedRows = new String[][]
+            {{"1","1","2"},
+             {"-1","1","0"},
+             {"2","2","4"},
+             {"-3","3","0"},
+             {"4","4","8"}};
+        JDBC.assertFullResultSet(rs, expectedRows);
+
+        s.executeUpdate("drop view v1");
+        s.executeUpdate("drop view v2");
+        s.executeUpdate("drop table t1");
+    }
 }