db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r1069661 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Fri, 11 Feb 2011 02:05:32 GMT
Author: dag
Date: Fri Feb 11 02:05:32 2011
New Revision: 1069661

URL: http://svn.apache.org/viewvc?rev=1069661&view=rev
Log:
DERBY-5005 Error when fully qualifying a field from a view in an ORDER BY clause

Patch derby-5005b. It makes FromSubquery implement its own
getFromTableByName instead of using the abstract superclass
FromTable's implementation which returns null when an explicit schema
is used (a view is represented a FromSubquery here), cf. the comment
in the default implementation:

"Only FromBaseTables have schema names"

which isn't quite true; views can have them, too.

Added a new test, lang.Derby5005Test instead of adding to the harness
test orderby.sql. Made a note in orderby.sql to merge with
Derby5005Test when that test gets rewritten to JUnit.


Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Derby5005Test.java
  (with props)
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromSubquery.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OrderByList.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/orderby.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/orderby.sql

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromSubquery.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromSubquery.java?rev=1069661&r1=1069660&r2=1069661&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromSubquery.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromSubquery.java Fri
Feb 11 02:05:32 2011
@@ -148,7 +148,19 @@ public class FromSubquery extends FromTa
 	protected FromTable getFromTableByName(String name, String schemaName, boolean exactMatch)
 		throws StandardException
 	{
-		return super.getFromTableByName(name, schemaName, exactMatch);
+        if (schemaName != null && origTableName != null) {
+            // View can have schema
+            if (!schemaName.equals(origTableName.schemaName)) {
+                return null;
+            }
+            // So far, so good, now go on to compare table name
+        }
+
+        if (getExposedName().equals(name)) {
+            return this;
+        }
+
+        return null;
 	}
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OrderByList.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OrderByList.java?rev=1069661&r1=1069660&r2=1069661&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OrderByList.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OrderByList.java Fri
Feb 11 02:05:32 2011
@@ -114,7 +114,7 @@ public class OrderByList extends Ordered
 
 	/**
 	 *	Bind the update columns by their names to the target resultset of the
-	 * cursor specification. This variant is used by InsertNode.
+     * cursor specification.
 	 *
 	 * 	@param target	The underlying result set
 	 *	@exception StandardException		Thrown on error

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/orderby.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/orderby.out?rev=1069661&r1=1069660&r2=1069661&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/orderby.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/orderby.out
Fri Feb 11 02:05:32 2011
@@ -2318,4 +2318,7 @@ ij> select k as s from d3303 group by i,
 ERROR 42X77: Column position '2' is out of range for the query expression.
 ij> drop table d3303;
 0 rows inserted/updated/deleted
+ij> -- See also Derby5005.java which should be merged with this test when
+-- it gets converted to JUnit.
+;
 ij> 

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Derby5005Test.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Derby5005Test.java?rev=1069661&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Derby5005Test.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Derby5005Test.java
Fri Feb 11 02:05:32 2011
@@ -0,0 +1,97 @@
+/*
+ * Class org.apache.derbyTesting.functionTests.tests.lang.Derby5005Test
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.derbyTesting.functionTests.tests.lang;
+
+import java.sql.SQLException;
+import java.sql.Statement;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+public class Derby5005Test extends BaseJDBCTestCase {
+
+    public Derby5005Test(String name) {
+        super(name);
+    }
+
+    /**
+     * Construct top level suite in this JUnit test
+     *
+     * @return A suite containing embedded and client suites.
+     */
+    public static Test suite()
+    {
+        TestSuite suite = new TestSuite("Derby5005Test");
+
+        suite.addTest(makeSuite());
+        // suite.addTest(
+        //      TestConfiguration.clientServerDecorator(makeSuite()));
+
+        return suite;
+    }
+
+    /**
+     * Construct suite of tests
+     *
+     * @return A suite containing the test cases.
+     */
+    private static Test makeSuite()
+    {
+        return new CleanDatabaseTestSetup(
+            new TestSuite(Derby5005Test.class)) {
+                protected void decorateSQL(Statement s)
+                        throws SQLException {
+                    getConnection().setAutoCommit(false);
+
+                    s.execute("create table app.a (a integer)");
+                    s.execute("create view app.v as select * from app.a");
+                    s.execute("insert into app.a (a) values(1)");
+
+                    getConnection().commit();
+                }
+            };
+    }
+
+    public void testInsertSelectOrderBy5005() throws SQLException {
+
+        Statement s = createStatement();
+
+        JDBC.assertFullResultSet(
+            s.executeQuery("select app.a.a from app.a where app.a.a <> 2 " +
+                           "order by app.a.a asc"),
+            new String[][]{{"1"}});
+
+        JDBC.assertFullResultSet(
+            s.executeQuery("select app.v.a from app.v where app.v.a <> 2 " +
+                           "order by v.a asc"),
+            new String[][]{{"1"}});
+
+        // Next query fails in DERBY-5005:
+        JDBC.assertFullResultSet(
+            s.executeQuery("select v.a from app.v where v.a <> 2 " +
+                           "order by app.v.a asc"),
+            new String[][]{{"1"}});
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Derby5005Test.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java?rev=1069661&r1=1069660&r2=1069661&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
Fri Feb 11 02:05:32 2011
@@ -217,6 +217,7 @@ public class _Suite extends BaseTestCase
         suite.addTest(SequenceGeneratorTest.suite());
         suite.addTest(OLAPTest.suite());
         suite.addTest(OrderByAndOffsetFetchInSubqueries.suite());
+        suite.addTest(Derby5005Test.suite());
         suite.addTest(AutoIncrementTest.suite());
         return suite;
 	}

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/orderby.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/orderby.sql?rev=1069661&r1=1069660&r2=1069661&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/orderby.sql
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/orderby.sql
Fri Feb 11 02:05:32 2011
@@ -901,3 +901,6 @@ select k from d3303 group by i,k order b
 select k as s from d3303 group by i,k order by 2;
 
 drop table d3303;
+
+-- See also Derby5005.java which should be merged with this test when
+-- it gets converted to JUnit.



Mime
View raw message