You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ddlutils-dev@db.apache.org by to...@apache.org on 2007/02/08 08:21:16 UTC

svn commit: r504811 - in /db/ddlutils/trunk/src: java/org/apache/ddlutils/platform/db2/Db2Builder.java test/org/apache/ddlutils/io/TestAlteration.java

Author: tomdz
Date: Wed Feb  7 23:21:15 2007
New Revision: 504811

URL: http://svn.apache.org/viewvc?view=rev&rev=504811
Log:
Fix for DDLUTILS-155

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2Builder.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2Builder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2Builder.java?view=diff&rev=504811&r1=504810&r2=504811
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2Builder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2Builder.java Wed Feb  7 23:21:15 2007
@@ -116,17 +116,26 @@
         }
         else
         {
+            String type = getSqlType(targetColumn);
+
             // DB2 has the limitation that it cannot convert numeric values
             // to VARCHAR, though it can convert them to CHAR
             if (TypeMap.isNumericType(sourceColumn.getTypeCode()) &&
                 "VARCHAR".equalsIgnoreCase(targetNativeType))
             {
-                targetNativeType = "CHAR";
+                Object sizeSpec = targetColumn.getSize();
+                
+                if (sizeSpec == null)
+                {
+                    sizeSpec = getPlatformInfo().getDefaultSize(targetColumn.getTypeCode());
+                }
+                type = "CHAR(" +sizeSpec.toString() + ")";
             }
 
-            print(targetNativeType);
-            print("(");
+            print("CAST(");
             printIdentifier(getColumnName(sourceColumn));
+            print(" AS ");
+            print(type);
             print(")");
         }
     }

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java?view=diff&rev=504811&r1=504810&r2=504811
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java Wed Feb  7 23:21:15 2007
@@ -83,9 +83,7 @@
     }
 
     /**
-     * Tests the alteration of a column datatype. Note that this test is known to fail on
-     * Derby and DB2 as they have no way to convert a numeric value to a VARCHAR, only to
-     * CHAR which will pad the value with spaces.
+     * Tests the alteration of a column datatype.
      */
     public void testChangeDatatype2()
     {