db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r292753 - in /db/ddlutils/trunk/src/java/org/apache/ddlutils/builder: MSSqlBuilder.java SybaseBuilder.java
Date Fri, 30 Sep 2005 14:41:49 GMT
Author: tomdz
Date: Fri Sep 30 07:41:41 2005
New Revision: 292753

URL: http://svn.apache.org/viewcvs?rev=292753&view=rev
Log:
Fix for DDLUTILS-21

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/MSSqlBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SybaseBuilder.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=292753&r1=292752&r2=292753&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 Fri Sep 30 07:41:41
2005
@@ -72,7 +72,7 @@
 
         writeQuotationOnStatement();
         print("IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = ");
-        printIdentifier(tableName);
+        printAlwaysQuotedIdentifier(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 = ");
-        printlnIdentifier(tableName);
+        printAlwaysQuotedIdentifier(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 = ");
-        printIdentifier(constraintName);
+        printAlwaysQuotedIdentifier(constraintName);
         println(")");
         printIndent();
         print("ALTER TABLE ");
@@ -222,6 +222,26 @@
         else
         {
             return "";
+        }
+    }
+
+    /**
+     * 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.
+     * 
+     * @param identifier The identifier
+     */
+    private void printAlwaysQuotedIdentifier(String identifier) throws IOException
+    {
+        if (!getPlatformInfo().isUseDelimitedIdentifiers())
+        {
+            print("'");
+        }
+        printIdentifier(identifier);
+        if (!getPlatformInfo().isUseDelimitedIdentifiers())
+        {
+            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=292753&r1=292752&r2=292753&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 Fri Sep 30 07:41:41
2005
@@ -68,7 +68,7 @@
     {
         writeQuotationOnStatement();
         print("IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = ");
-        printIdentifier(getTableName(table));
+        printAlwaysQuotedIdentifier(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 = ");
-        printIdentifier(constraintName);
+        printAlwaysQuotedIdentifier(constraintName);
         println(")");
         printIndent();
         print("ALTER TABLE ");
@@ -155,6 +155,26 @@
         else
         {
             return "";
+        }
+    }
+
+    /**
+     * 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.
+     * 
+     * @param identifier The identifier
+     */
+    private void printAlwaysQuotedIdentifier(String identifier) throws IOException
+    {
+        if (!getPlatformInfo().isUseDelimitedIdentifiers())
+        {
+            print("'");
+        }
+        printIdentifier(identifier);
+        if (!getPlatformInfo().isUseDelimitedIdentifiers())
+        {
+            print("'");
         }
     }
 }



Mime
View raw message