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 ka...@apache.org on 2011/04/01 12:45:32 UTC

svn commit: r1087641 - in /db/derby/code/trunk/java: engine/org/apache/derby/catalog/types/SynonymAliasInfo.java testing/org/apache/derbyTesting/functionTests/tests/lang/SynonymTest.java

Author: kahatlen
Date: Fri Apr  1 10:45:32 2011
New Revision: 1087641

URL: http://svn.apache.org/viewvc?rev=1087641&view=rev
Log:
DERBY-5168: Wrong syntax in identifier chain returned by SynonymAliasInfo.toString()

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/SynonymAliasInfo.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SynonymTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/SynonymAliasInfo.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/SynonymAliasInfo.java?rev=1087641&r1=1087640&r2=1087641&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/SynonymAliasInfo.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/SynonymAliasInfo.java Fri Apr  1 10:45:32 2011
@@ -23,6 +23,7 @@ package org.apache.derby.catalog.types;
 
 import org.apache.derby.iapi.services.io.Formatable;
 import org.apache.derby.iapi.services.io.StoredFormatIds;
+import org.apache.derby.iapi.util.IdUtil;
 import org.apache.derby.catalog.AliasInfo;
 import java.io.IOException;
 import java.io.ObjectInput;
@@ -99,7 +100,7 @@ public class SynonymAliasInfo implements
 	public	int	getTypeFormatId()	{ return StoredFormatIds.SYNONYM_INFO_V01_ID; }
 
 	public String toString() {
-		return "\"" + schemaName + "\".\"" + tableName + "\"";
+        return IdUtil.mkQualifiedName(schemaName, tableName);
 	}
 
 	public String getMethodName()

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SynonymTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SynonymTest.java?rev=1087641&r1=1087640&r2=1087641&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SynonymTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SynonymTest.java Fri Apr  1 10:45:32 2011
@@ -28,6 +28,7 @@ import junit.framework.TestSuite;
 
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.JDBC;
 
 /**
  * Synonym testing using junit
@@ -92,4 +93,26 @@ public class SynonymTest extends BaseJDB
         st.executeUpdate("drop schema test2 restrict");
         st.executeUpdate("drop schema test1 restrict");
     }
+
+    /**
+     * Verify the fix for DERBY-5168. SynonymAliasInfo.toString() used to
+     * return a value with incorrect syntax if the synonym referred to a
+     * table that had a double quote character either in its name or in the
+     * schema name.
+     */
+    public void testSynonymsForTablesWithDoubleQuotes() throws SQLException {
+        setAutoCommit(false);
+        Statement s = createStatement();
+        s.execute("create schema \"\"\"\"");
+        s.execute("create table \"\"\"\".\"\"\"\" (x int)");
+        s.execute("create synonym derby_5168_synonym for \"\"\"\".\"\"\"\"");
+
+        // We can exercise SynonymAliasInfo.toString() by reading the ALIASINFO
+        // column in SYS.SYSALIASES. This assert used to fail before the fix.
+        JDBC.assertSingleValueResultSet(
+            s.executeQuery(
+                "select aliasinfo from sys.sysaliases " +
+                "where alias = 'DERBY_5168_SYNONYM'"),
+            "\"\"\"\".\"\"\"\"");
+    }
 }