db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r405862 - in /db/ddlutils/trunk/src/java/org/apache/ddlutils: model/Column.java platform/SqlBuilder.java platform/sybase/SybaseBuilder.java
Date Fri, 12 May 2006 20:33:20 GMT
Author: tomdz
Date: Fri May 12 13:33:20 2006
New Revision: 405862

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

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Column.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybaseBuilder.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Column.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Column.java?rev=405862&r1=405861&r2=405862&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Column.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Column.java Fri May 12 13:33:20 2006
@@ -412,7 +412,7 @@
      */
     public Object getParsedDefaultValue()
     {
-        if (_defaultValue != null)
+        if ((_defaultValue != null) && (_defaultValue.length() > 0))
         {
             try
             {
@@ -451,9 +451,13 @@
                 }
             }
             catch (NumberFormatException ex)
-            {}
+            {
+                return null;
+            }
             catch (IllegalArgumentException ex)
-            {}
+            {
+                return null;
+            }
         }
         return _defaultValue;
     }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java?rev=405862&r1=405861&r2=405862&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java Fri May 12 13:33:20
2006
@@ -1958,18 +1958,7 @@
         printIdentifier(getColumnName(column));
         print(" ");
         print(getSqlType(column));
-
-        if ((column.getDefaultValue() != null) ||
-            (getPlatformInfo().isDefaultValueUsedForIdentitySpec() && column.isAutoIncrement()))
-        {
-            if (!getPlatformInfo().isDefaultValuesForLongTypesSupported() && 
-                ((column.getTypeCode() == Types.LONGVARBINARY) || (column.getTypeCode() ==
Types.LONGVARCHAR)))
-            {
-                throw new DynaSqlException("The platform does not support default values
for LONGVARCHAR or LONGVARBINARY columns");
-            }
-            print(" DEFAULT ");
-            writeColumnDefaultValue(table, column);
-        }
+        writeColumnDefaultValueStmt(table, column);
         if (column.isRequired())
         {
             print(" ");
@@ -2120,7 +2109,39 @@
         }
         return result;
     }
-    
+
+    /**
+     * Prints the default value stmt part for the column.
+     * 
+     * @param table  The table
+     * @param column The column
+     */ 
+    protected void writeColumnDefaultValueStmt(Table table, Column column) throws IOException
+    {
+        Object parsedDefault = column.getParsedDefaultValue();
+
+        if (parsedDefault != null)
+        {
+            if (!getPlatformInfo().isDefaultValuesForLongTypesSupported() && 
+                ((column.getTypeCode() == Types.LONGVARBINARY) || (column.getTypeCode() ==
Types.LONGVARCHAR)))
+            {
+                throw new DynaSqlException("The platform does not support default values
for LONGVARCHAR or LONGVARBINARY columns");
+            }
+            // we write empty default value strings only if the type is not a numeric or
date/time type
+            if ((column.getDefaultValue().length() > 0) ||
+                (!TypeMap.isNumericType(column.getTypeCode()) && !TypeMap.isDateTimeType(column.getTypeCode())))
+            {
+                print(" DEFAULT ");
+                writeColumnDefaultValue(table, column);
+            }
+        }
+        else if (getPlatformInfo().isDefaultValueUsedForIdentitySpec() && column.isAutoIncrement())
+        {
+            print(" DEFAULT ");
+            writeColumnDefaultValue(table, column);
+        }
+    }
+
     /**
      * Prints the default value of the column.
      * 

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybaseBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybaseBuilder.java?rev=405862&r1=405861&r2=405862&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybaseBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybaseBuilder.java Fri
May 12 13:33:20 2006
@@ -22,7 +22,6 @@
 import java.sql.Types;
 import java.util.Map;
 
-import org.apache.ddlutils.DynaSqlException;
 import org.apache.ddlutils.Platform;
 import org.apache.ddlutils.model.Column;
 import org.apache.ddlutils.model.Database;
@@ -68,17 +67,7 @@
         printIdentifier(getColumnName(column));
         print(" ");
         print(getSqlType(column));
-
-        if (column.getDefaultValue() != null)
-        {
-            if (!getPlatformInfo().isDefaultValuesForLongTypesSupported() && 
-                ((column.getTypeCode() == Types.LONGVARBINARY) || (column.getTypeCode() ==
Types.LONGVARCHAR)))
-            {
-                throw new DynaSqlException("The platform does not support default values
for LONGVARCHAR or LONGVARBINARY columns");
-            }
-            print(" DEFAULT ");
-            writeColumnDefaultValue(table, column);
-        }
+        writeColumnDefaultValueStmt(table, column);
         // Sybase does not like NOT NULL and IDENTITY together
         if (column.isRequired() && !column.isAutoIncrement())
         {



Mime
View raw message