-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Shreyas & I worked through his Derby-13 patch off this list to come to a
conclusion. The summary of that discussion is:
- - I had misunderstood that FromTable.getTableName() already handled the
correlation name, return a TableName of <null,correlationName> in that
case. I had thought that it returned the underlying actual table name.
Once Shreyas pointed that out I started to understand his fix. I do
think that beyond this patch there is some cleanup in this area as if
getTableName() encapsulates exposed name handling, then there should be
no need for any public getExposedName methods.
- - I then questioned when FromTable.getTableName() could return null as
Shreyas was checking for it in the changes in FromList. He re-ran the
tests without the check and hit an exception in lojreorder.sql. Looking
at that I pointed out that the correct check would be if the FromTable
is an instanceof TableOperatorNode, which would map the existing check.
- - and the final change was to not re-build TableName objects in the
FromList duplicate exposed name checking, but use the objects directly
from FromList.getTableName() as TableName objects are re-useable
- - Shreyas also provided some test cases which I added to the existing
select.sql test.
- - I also removed the modifications to TableName from the patch as they
were only cosmetic.
I will commit this tomorrow if there are no other review comments on the
patch.
Dan.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFB8EOcIv0S4qsbfuQRAiYFAJ9ytZTHpNjmJp3qLfSKa0oGh6iWVwCfa5td
fW5smzisdhTyfo6Orl1fbS0=
=h8qk
-----END PGP SIGNATURE-----
Index: java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java
===================================================================
--- java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java
(revision 125795)
+++ java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java
(working copy)
@@ -493,7 +493,7 @@
*
* @exception StandardException Thrown on error
*/
- public ResultColumnList getAllResultColumns(String allTableName)
+ public ResultColumnList getAllResultColumns(TableName allTableName)
throws StandardException
{
if (SanityManager.DEBUG)
Index: java/engine/org/apache/derby/impl/sql/compile/FromTable.java
===================================================================
--- java/engine/org/apache/derby/impl/sql/compile/FromTable.java
(revision 125795)
+++ java/engine/org/apache/derby/impl/sql/compile/FromTable.java
(working copy)
@@ -32,12 +32,7 @@
import org.apache.derby.iapi.sql.compile.RowOrdering;
import org.apache.derby.iapi.sql.compile.C_NodeTypes;
-import org.apache.derby.iapi.sql.dictionary.DataDictionary;
-import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext;
-import org.apache.derby.iapi.sql.dictionary.ColumnDescriptor;
-import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
-import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
-import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
+import org.apache.derby.iapi.sql.dictionary.*;
import org.apache.derby.iapi.types.DataTypeDescriptor;
@@ -52,6 +47,7 @@
import org.apache.derby.iapi.util.JBitSet;
import org.apache.derby.iapi.services.io.FormatableBitSet;
import org.apache.derby.iapi.util.StringUtil;
+import org.apache.derby.catalog.UUID;
import java.util.Enumeration;
import java.util.Properties;
@@ -958,7 +954,7 @@
*
* @exception StandardException Thrown on error
*/
- public ResultColumnList getResultColumnsForList(String allTableName,
+ public ResultColumnList getResultColumnsForList(TableName allTableName,
ResultColumnList inputRcl,
TableName tableName)
throws StandardException
@@ -968,15 +964,27 @@
ValueNode valueNode;
String columnName;
TableName exposedName;
+ TableName toCompare;
- /* If allTableName is non-null, then we must check to see if it
matches
+ /* If allTableName is non-null, then we must check to see if it
matches
* our exposed name.
*/
- if (allTableName != null && !
allTableName.equals(getExposedName()))
- {
- return null;
- }
+ if(correlationName == null)
+ toCompare = tableName;
+ else {
+ if(allTableName != null)
+ toCompare =
makeTableName(allTableName.getSchemaName(),correlationName);
+ else
+ toCompare = makeTableName(null,correlationName);
+ }
+
+ if ( allTableName != null &&
+ ! allTableName.equals(toCompare))
+ {
+ return null;
+ }
+
/* Cache exposed name for this table.
* The exposed name becomes the qualifier for each column
* in the expanded list.
Index: java/engine/org/apache/derby/impl/sql/compile/FromSubquery.java
===================================================================
--- java/engine/org/apache/derby/impl/sql/compile/FromSubquery.java
(revision 125795)
+++ java/engine/org/apache/derby/impl/sql/compile/FromSubquery.java
(working copy)
@@ -626,17 +626,24 @@
* result columns from the subquery.
* @exception StandardException Thrown on error
*/
- public ResultColumnList getAllResultColumns(String allTableName)
+ public ResultColumnList getAllResultColumns(TableName allTableName)
throws StandardException
{
ResultColumnList rcList = null;
TableName exposedName;
+ TableName toCompare;
- if (allTableName != null && !
allTableName.equals(getExposedName()))
- {
- return null;
- }
+ if(allTableName != null)
+ toCompare =
makeTableName(allTableName.getSchemaName(),correlationName);
+ else
+ toCompare = makeTableName(null,correlationName);
+
+ if ( allTableName != null &&
+ ! allTableName.equals(toCompare))
+ {
+ return null;
+ }
/* Cache exposed name for this table.
* The exposed name becomes the qualifier for each column
Index: java/engine/org/apache/derby/impl/sql/compile/AllResultColumn.java
===================================================================
--- java/engine/org/apache/derby/impl/sql/compile/AllResultColumn.java
(revision 125795)
+++ java/engine/org/apache/derby/impl/sql/compile/AllResultColumn.java
(working copy)
@@ -87,4 +87,9 @@
tableName,
getContextManager());
}
+
+
+ public TableName getTableNameObject() {
+ return tableName;
+ }
}
Index: java/engine/org/apache/derby/impl/sql/compile/ResultColumn.java
===================================================================
--- java/engine/org/apache/derby/impl/sql/compile/ResultColumn.java
(revision 125795)
+++ java/engine/org/apache/derby/impl/sql/compile/ResultColumn.java
(working copy)
@@ -1730,4 +1730,8 @@
}
return dtd;
} // end of getTypeServices
+
+ public TableName getTableNameObject() {
+ return null;
+ }
}
Index: java/engine/org/apache/derby/impl/sql/compile/FromList.java
===================================================================
--- java/engine/org/apache/derby/impl/sql/compile/FromList.java (revision
125795)
+++ java/engine/org/apache/derby/impl/sql/compile/FromList.java (working copy)
@@ -136,14 +136,24 @@
* user is executing a really dumb query and we won't throw
* and exception - consider it an ANSI extension.
*/
+ TableName leftTable = null;
+ TableName rightTable = null;
if (! (fromTable instanceof TableOperatorNode))
{
/* Check for duplicate table name in FROM list */
int size = size();
for (int index = 0; index < size; index++)
{
- if (fromTable.getExposedName().equals
- (((FromTable)
elementAt(index)).getExposedName()) )
+ leftTable = fromTable.getTableName();
+
+ if(((FromTable) elementAt(index)) instanceof
TableOperatorNode) {
+ continue;
+ }
+
+ else {
+ rightTable = ((FromTable) elementAt(index)).getTableName();
+ }
+ if(leftTable.equals(rightTable))
{
throw
StandardException.newException(SQLState.LANG_FROM_LIST_DUPLICATE_TABLE_NAME,
fromTable.getExposedName());
}
@@ -380,7 +390,7 @@
*
* @exception StandardException Thrown on error
*/
- public ResultColumnList expandAll(String allTableName)
+ public ResultColumnList expandAll(TableName allTableName)
throws StandardException
{
ResultColumnList resultColumnList = null;
Index: java/engine/org/apache/derby/impl/sql/compile/JoinNode.java
===================================================================
--- java/engine/org/apache/derby/impl/sql/compile/JoinNode.java (revision
125795)
+++ java/engine/org/apache/derby/impl/sql/compile/JoinNode.java (working copy)
@@ -359,7 +359,7 @@
*
* @exception StandardException Thrown on error
*/
- public ResultColumnList getAllResultColumns(String allTableName)
+ public ResultColumnList getAllResultColumns(TableName allTableName)
throws StandardException
{
/* We need special processing when there is a USING clause.
@@ -453,7 +453,7 @@
*
* @exception StandardException Thrown on error
*/
- private ResultColumnList getAllResultColumnsNoUsing(String allTableName)
+ private ResultColumnList getAllResultColumnsNoUsing(TableName
allTableName)
throws StandardException
{
ResultColumnList leftRCL =
leftResultSet.getAllResultColumns(allTableName);
Index: java/engine/org/apache/derby/impl/sql/compile/FromVTI.java
===================================================================
--- java/engine/org/apache/derby/impl/sql/compile/FromVTI.java (revision
125795)
+++ java/engine/org/apache/derby/impl/sql/compile/FromVTI.java (working copy)
@@ -901,19 +901,26 @@
* result columns from the subquery.
* @exception StandardException Thrown on error
*/
- public ResultColumnList getAllResultColumns(String allTableName)
+ public ResultColumnList getAllResultColumns(TableName allTableName)
throws StandardException
{
ResultColumnList rcList = null;
ResultColumn resultColumn;
ValueNode valueNode;
String columnName;
+ TableName toCompare;
- if (allTableName != null && !
allTableName.equals(getExposedName()))
- {
- return null;
- }
+ if(allTableName != null)
+ toCompare =
makeTableName(allTableName.getSchemaName(),correlationName);
+ else
+ toCompare = makeTableName(null,correlationName);
+ if ( allTableName != null &&
+ ! allTableName.equals(toCompare))
+ {
+ return null;
+ }
+
rcList = (ResultColumnList) getNodeFactory().getNode(
C_NodeTypes.RESULT_COLUMN_LIST,
getContextManager());
Index: java/engine/org/apache/derby/impl/sql/compile/FromBaseTable.java
===================================================================
--- java/engine/org/apache/derby/impl/sql/compile/FromBaseTable.java
(revision 125795)
+++ java/engine/org/apache/derby/impl/sql/compile/FromBaseTable.java
(working copy)
@@ -3412,7 +3412,7 @@
*
* @exception StandardException Thrown on error
*/
- public ResultColumnList getAllResultColumns(String allTableName)
+ public ResultColumnList getAllResultColumns(TableName allTableName)
throws StandardException
{
return getResultColumnsForList(allTableName, resultColumns,
tableName);
Index: java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
===================================================================
--- java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
(revision 125795)
+++ java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
(working copy)
@@ -1451,7 +1451,7 @@
{
boolean expanded = false;
ResultColumnList allExpansion;
- String fullTableName;
+ TableName fullTableName;
/* First walk result column list looking for *'s to expand */
for (int index = 0; index < size(); index++)
@@ -1461,7 +1461,15 @@
{
expanded = true;
- fullTableName = ((AllResultColumn)
rc).getFullTableName();
+ //fullTableName = ((AllResultColumn)
rc).getFullTableName();
+ TableName temp = rc.getTableNameObject();
+ if(temp != null) {
+ String sName = temp.getSchemaName();
+ String tName = temp.getTableName();
+ fullTableName = makeTableName(sName,tName);
+ }
+ else
+ fullTableName = null;
allExpansion =
fromList.expandAll(fullTableName);
/* Make sure that every column has a name */
Index: java/testing/org/apache/derbyTesting/functionTests/tests/lang/select.sql
===================================================================
--- java/testing/org/apache/derbyTesting/functionTests/tests/lang/select.sql
(revision 125795)
+++ java/testing/org/apache/derbyTesting/functionTests/tests/lang/select.sql
(working copy)
@@ -102,3 +102,22 @@
drop table content.style;
drop table content.keygen;
drop schema content restrict;
+
+
+-- This is to test quotes handling in tables.
+-- This tests patch for Derby 13
+
+create table "S1.T1" (id int not null primary key, d1 int);
+
+create schema s1;
+create table s1.t1 (id int not null primary key, d2 int);
+
+select * from s1.t1, "S1.T1" where s1.t1.id = "S1.T1".id;
+
+select s1.t1.* from "S1.T1";
+
+select "S1.T1".* from s1.t1;
+
+select * from "S1.T1" , APP."S1.T1";
+
+select "S1.T1".d1 from "S1.T1", APP."S1.T1";
Index: java/testing/org/apache/derbyTesting/functionTests/master/select.out
===================================================================
--- java/testing/org/apache/derbyTesting/functionTests/master/select.out
(revision 125795)
+++ java/testing/org/apache/derbyTesting/functionTests/master/select.out
(working copy)
@@ -160,4 +160,23 @@
0 rows inserted/updated/deleted
ij> drop schema content restrict;
0 rows inserted/updated/deleted
+ij> -- This is to test quotes handling in tables.
+-- This tests patch for Derby 13
+create table "S1.T1" (id int not null primary key, d1 int);
+0 rows inserted/updated/deleted
+ij> create schema s1;
+0 rows inserted/updated/deleted
+ij> create table s1.t1 (id int not null primary key, d2 int);
+0 rows inserted/updated/deleted
+ij> select * from s1.t1, "S1.T1" where s1.t1.id = "S1.T1".id;
+ID |D2 |ID |D1
+-----------------------------------------------
+ij> select s1.t1.* from "S1.T1";
+ERROR 42X10: 'S1.T1' is not an exposed table name in the scope in which it
appears.
+ij> select "S1.T1".* from s1.t1;
+ERROR 42X10: 'S1.T1' is not an exposed table name in the scope in which it
appears.
+ij> select * from "S1.T1" , APP."S1.T1";
+ERROR 42X09: The table or alias name 'APP.S1.T1' is used more than once in the
FROM list.
+ij> select "S1.T1".d1 from "S1.T1", APP."S1.T1";
+ERROR 42X09: The table or alias name 'APP.S1.T1' is used more than once in the
FROM list.
ij>