db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r293549 - in /db/ddlutils/trunk/src: java/org/apache/ddlutils/builder/ test/org/apache/ddlutils/platform/
Date Tue, 04 Oct 2005 06:28:02 GMT
Author: tomdz
Date: Mon Oct  3 23:27:51 2005
New Revision: 293549

URL: http://svn.apache.org/viewcvs?rev=293549&view=rev
Log:
Fix for DDLUTILS-21 which ensures that for Microsoft SQL Server and Sybase, identifiers are
always enclosed in single quotes when used for comparison in a WHERE clause (regardless of
whether delimited identifiers are used)

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/MSSqlBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SybaseBuilder.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestMSSqlPlatform.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestSybasePlatform.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/MSSqlBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/MSSqlBuilder.java?rev=293549&r1=293548&r2=293549&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/MSSqlBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/MSSqlBuilder.java Mon Oct  3 23:27:51
2005
@@ -72,7 +72,7 @@
 
         writeQuotationOnStatement();
         print("IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = ");
-        printAlwaysQuotedIdentifier(tableName);
+        printAlwaysSingleQuotedIdentifier(tableName);
         println(")");
         println("BEGIN");
         println("     DECLARE @reftable nvarchar(60), @constraintname nvarchar(60)");
@@ -86,7 +86,7 @@
         println("         and cons.id = ref.constid");
         println("         and reftables.id = ref.fkeyid");
         print("         and tables.name = ");
-        printAlwaysQuotedIdentifier(tableName);
+        printAlwaysSingleQuotedIdentifier(tableName);
         println("     OPEN refcursor");
         println("     FETCH NEXT from refcursor into @reftable, @constraintname");
         println("     while @@FETCH_STATUS = 0");
@@ -162,7 +162,7 @@
         String constraintName = foreignKey.getName() == null ? getConstraintName(null, table,
"FK", getForeignKeyName(foreignKey)) : foreignKey.getName();
 
         print("IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'RI' AND name = ");
-        printAlwaysQuotedIdentifier(constraintName);
+        printAlwaysSingleQuotedIdentifier(constraintName);
         println(")");
         printIndent();
         print("ALTER TABLE ");
@@ -226,22 +226,15 @@
     }
 
     /**
-     * Prints the given identifier with enforced quotes. If delimited identifiers are
-     * turned on, this will use the normal {@link SqlBuilder#printIdentifier(String)}
-     * method. If not, single quotation marks are used around the identifier.
+     * Prints the given identifier with enforced single quotes around it regardless of whether

+     * delimited identifiers are turned on or not.
      * 
      * @param identifier The identifier
      */
-    private void printAlwaysQuotedIdentifier(String identifier) throws IOException
+    private void printAlwaysSingleQuotedIdentifier(String identifier) throws IOException
     {
-        if (!getPlatformInfo().isUseDelimitedIdentifiers())
-        {
-            print("'");
-        }
-        printIdentifier(identifier);
-        if (!getPlatformInfo().isUseDelimitedIdentifiers())
-        {
-            print("'");
-        }
+        print("'");
+        print(identifier);
+        print("'");
     }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SybaseBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SybaseBuilder.java?rev=293549&r1=293548&r2=293549&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SybaseBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SybaseBuilder.java Mon Oct  3 23:27:51
2005
@@ -68,7 +68,7 @@
     {
         writeQuotationOnStatement();
         print("IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = ");
-        printAlwaysQuotedIdentifier(getTableName(table));
+        printAlwaysSingleQuotedIdentifier(getTableName(table));
         println(")");
         println("BEGIN");
         printIndent();
@@ -86,7 +86,7 @@
         String constraintName = foreignKey.getName() == null ? getConstraintName(null, table,
"FK", getForeignKeyName(foreignKey)) : foreignKey.getName();
 
         print("IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'RI' AND name = ");
-        printAlwaysQuotedIdentifier(constraintName);
+        printAlwaysSingleQuotedIdentifier(constraintName);
         println(")");
         printIndent();
         print("ALTER TABLE ");
@@ -159,22 +159,15 @@
     }
 
     /**
-     * Prints the given identifier with enforced quotes. If delimited identifiers are
-     * turned on, this will use the normal {@link SqlBuilder#printIdentifier(String)}
-     * method. If not, single quotation marks are used around the identifier.
+     * Prints the given identifier with enforced single quotes around it regardless of whether

+     * delimited identifiers are turned on or not.
      * 
      * @param identifier The identifier
      */
-    private void printAlwaysQuotedIdentifier(String identifier) throws IOException
+    private void printAlwaysSingleQuotedIdentifier(String identifier) throws IOException
     {
-        if (!getPlatformInfo().isUseDelimitedIdentifiers())
-        {
-            print("'");
-        }
-        printIdentifier(identifier);
-        if (!getPlatformInfo().isUseDelimitedIdentifiers())
-        {
-            print("'");
-        }
+        print("'");
+        print(identifier);
+        print("'");
     }
 }

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestMSSqlPlatform.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestMSSqlPlatform.java?rev=293549&r1=293548&r2=293549&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestMSSqlPlatform.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestMSSqlPlatform.java Mon Oct
 3 23:27:51 2005
@@ -43,7 +43,7 @@
         assertEqualsIgnoringWhitespaces(
             "SET quoted_identifier on;\n"+
             "SET quoted_identifier on;\n"+
-            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = \"coltype\")\n"+
+            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = 'coltype')\n"+
             "BEGIN\n"+
             "     DECLARE @reftable nvarchar(60), @constraintname nvarchar(60)\n"+
             "     DECLARE refcursor CURSOR FOR\n"+
@@ -55,7 +55,7 @@
             "       where tables.id = ref.rkeyid\n"+
             "         and cons.id = ref.constid\n"+
             "         and reftables.id = ref.fkeyid\n"+
-            "         and tables.name = \"coltype\"\n"+
+            "         and tables.name = 'coltype'\n"+
             "     OPEN refcursor\n"+
             "     FETCH NEXT from refcursor into @reftable, @constraintname\n"+
             "     while @@FETCH_STATUS = 0\n"+
@@ -115,7 +115,7 @@
         assertEqualsIgnoringWhitespaces(
             "SET quoted_identifier on;\n"+
             "SET quoted_identifier on;\n"+
-            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = \"constraints\")\n"+
+            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = 'constraints')\n"+
             "BEGIN\n"+
             "     DECLARE @reftable nvarchar(60), @constraintname nvarchar(60)\n"+
             "     DECLARE refcursor CURSOR FOR\n"+
@@ -127,7 +127,7 @@
             "       where tables.id = ref.rkeyid\n"+
             "         and cons.id = ref.constid\n"+
             "         and reftables.id = ref.fkeyid\n"+
-            "         and tables.name = \"constraints\"\n"+
+            "         and tables.name = 'constraints'\n"+
             "     OPEN refcursor\n"+
             "     FETCH NEXT from refcursor into @reftable, @constraintname\n"+
             "     while @@FETCH_STATUS = 0\n"+
@@ -160,14 +160,14 @@
     {
         assertEqualsIgnoringWhitespaces(
             "SET quoted_identifier on;\n"+
-            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'RI' AND name = \"testfk\")\n"+
+            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'RI' AND name = 'testfk')\n"+
             "     ALTER TABLE \"table3\" DROP CONSTRAINT \"testfk\";\n"+
             "SET quoted_identifier on;\n"+
-            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'RI' AND name = \"table2_FK_COL_FK_1_COL_FK_2_table1\")\n"+
+            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'RI' AND name = 'table2_FK_COL_FK_1_COL_FK_2_table1')\n"+
             "     ALTER TABLE \"table2\" DROP CONSTRAINT \"table2_FK_COL_FK_1_COL_FK_2_table1\";\n"+
             "SET quoted_identifier on;\n"+
             "SET quoted_identifier on;\n"+
-            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = \"table3\")\n"+
+            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = 'table3')\n"+
             "BEGIN\n"+
             "     DECLARE @reftable nvarchar(60), @constraintname nvarchar(60)\n"+
             "     DECLARE refcursor CURSOR FOR\n"+
@@ -179,7 +179,7 @@
             "       where tables.id = ref.rkeyid\n"+
             "         and cons.id = ref.constid\n"+
             "         and reftables.id = ref.fkeyid\n"+
-            "         and tables.name = \"table3\"\n"+
+            "         and tables.name = 'table3'\n"+
             "     OPEN refcursor\n"+
             "     FETCH NEXT from refcursor into @reftable, @constraintname\n"+
             "     while @@FETCH_STATUS = 0\n"+
@@ -192,7 +192,7 @@
             "     DROP TABLE \"table3\"\n"+
             "END;\n"+
             "SET quoted_identifier on;\n"+
-            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = \"table2\")\n"+
+            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = 'table2')\n"+
             "BEGIN\n"+
             "     DECLARE @reftable nvarchar(60), @constraintname nvarchar(60)\n"+
             "     DECLARE refcursor CURSOR FOR\n"+
@@ -204,7 +204,7 @@
             "       where tables.id = ref.rkeyid\n"+
             "         and cons.id = ref.constid\n"+
             "         and reftables.id = ref.fkeyid\n"+
-            "         and tables.name = \"table2\"\n"+
+            "         and tables.name = 'table2'\n"+
             "     OPEN refcursor\n"+
             "     FETCH NEXT from refcursor into @reftable, @constraintname\n"+
             "     while @@FETCH_STATUS = 0\n"+
@@ -217,7 +217,7 @@
             "     DROP TABLE \"table2\"\n"+
             "END;\n"+
             "SET quoted_identifier on;\n"+
-            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = \"table1\")\n"+
+            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = 'table1')\n"+
             "BEGIN\n"+
             "     DECLARE @reftable nvarchar(60), @constraintname nvarchar(60)\n"+
             "     DECLARE refcursor CURSOR FOR\n"+
@@ -229,7 +229,7 @@
             "       where tables.id = ref.rkeyid\n"+
             "         and cons.id = ref.constid\n"+
             "         and reftables.id = ref.fkeyid\n"+
-            "         and tables.name = \"table1\"\n"+
+            "         and tables.name = 'table1'\n"+
             "     OPEN refcursor\n"+
             "     FETCH NEXT from refcursor into @reftable, @constraintname\n"+
             "     while @@FETCH_STATUS = 0\n"+

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestSybasePlatform.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestSybasePlatform.java?rev=293549&r1=293548&r2=293549&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestSybasePlatform.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestSybasePlatform.java Mon Oct
 3 23:27:51 2005
@@ -43,7 +43,7 @@
         assertEqualsIgnoringWhitespaces(
             "SET quoted_identifier on;\n"+
             "SET quoted_identifier on;\n"+
-            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = \"coltype\")\n"+
+            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = 'coltype')\n"+
             "BEGIN\n"+
             "    DROP TABLE \"coltype\"\n"+
             "END;\n"+
@@ -94,7 +94,7 @@
         assertEqualsIgnoringWhitespaces(
             "SET quoted_identifier on;\n"+
             "SET quoted_identifier on;\n"+
-            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = \"constraints\")\n"+
+            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = 'constraints')\n"+
             "BEGIN\n"+
             "    DROP TABLE \"constraints\"\n"+
             "END;\n"+
@@ -119,24 +119,24 @@
     {
         assertEqualsIgnoringWhitespaces(
             "SET quoted_identifier on;\n"+
-            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'RI' AND name = \"testfk\")\n"+
+            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'RI' AND name = 'testfk')\n"+
             "    ALTER TABLE \"table3\" DROP CONSTRAINT \"testfk\";\n"+
             "SET quoted_identifier on;\n"+
-            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'RI' AND name = \"table2_FK_COL_F_OL_FK_2_table1\")\n"+
+            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'RI' AND name = 'table2_FK_COL_F_OL_FK_2_table1')\n"+
             "    ALTER TABLE \"table2\" DROP CONSTRAINT \"table2_FK_COL_F_OL_FK_2_table1\";\n"+
             "SET quoted_identifier on;\n"+
             "SET quoted_identifier on;\n"+
-            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = \"table3\")\n"+
+            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = 'table3')\n"+
             "BEGIN\n"+
             "    DROP TABLE \"table3\"\n"+
             "END;\n"+
             "SET quoted_identifier on;\n"+
-            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = \"table2\")\n"+
+            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = 'table2')\n"+
             "BEGIN\n"+
             "    DROP TABLE \"table2\"\n"+
             "END;\n"+
             "SET quoted_identifier on;\n"+
-            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = \"table1\")\n"+
+            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = 'table1')\n"+
             "BEGIN\n"+
             "    DROP TABLE \"table1\"\n"+
             "END;\n"+



Mime
View raw message