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 2008/11/06 00:41:59 UTC

svn commit: r711742 - in /db/ddlutils/trunk/src: main/java/org/apache/ddlutils/platform/mssql/MSSqlBuilder.java test/java/org/apache/ddlutils/io/TestMisc.java

Author: tomdz
Date: Wed Nov  5 15:41:59 2008
New Revision: 711742

URL: http://svn.apache.org/viewvc?rev=711742&view=rev
Log:
Fixed some Sql Server platform bugs

Modified:
    db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/mssql/MSSqlBuilder.java
    db/ddlutils/trunk/src/test/java/org/apache/ddlutils/io/TestMisc.java

Modified: db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/mssql/MSSqlBuilder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/mssql/MSSqlBuilder.java?rev=711742&r1=711741&r2=711742&view=diff
==============================================================================
--- db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/mssql/MSSqlBuilder.java (original)
+++ db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/mssql/MSSqlBuilder.java Wed Nov  5 15:41:59 2008
@@ -351,9 +351,16 @@
     {
         // Sql Server per default does not allow us to insert values explicitly into
         // identity columns. However, we can change this behavior
-        boolean hasIdentityColumns = targetTable.getAutoIncrementColumns().length > 0;
+        // We need to this only if
+        // - there is a column in both tables that is auto increment only in the target table, or
+        // - there is a column in both tables that is auto increment in both tables
+        Column[] targetIdentityColumns = targetTable.getAutoIncrementColumns();
+
+        // Sql Server allows only one identity column, so let's take a shortcut here
+        boolean needToAllowIdentityInsert = (targetIdentityColumns.length > 0) &&
+                                            (sourceTable.findColumn(targetIdentityColumns[0].getName(), getPlatform().isDelimitedIdentifierModeOn()) != null);
 
-        if (hasIdentityColumns)
+        if (needToAllowIdentityInsert)
         {
             print("SET IDENTITY_INSERT ");
             printIdentifier(getTableName(targetTable));
@@ -362,7 +369,7 @@
         }
         super.copyData(sourceTable, targetTable);
         // We have to turn it off ASAP because it can be on only for one table per session
-        if (hasIdentityColumns)
+        if (needToAllowIdentityInsert)
         {
             print("SET IDENTITY_INSERT ");
             printIdentifier(getTableName(targetTable));

Modified: db/ddlutils/trunk/src/test/java/org/apache/ddlutils/io/TestMisc.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/java/org/apache/ddlutils/io/TestMisc.java?rev=711742&r1=711741&r2=711742&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/java/org/apache/ddlutils/io/TestMisc.java (original)
+++ db/ddlutils/trunk/src/test/java/org/apache/ddlutils/io/TestMisc.java Wed Nov  5 15:41:59 2008
@@ -37,6 +37,7 @@
 import org.apache.ddlutils.model.Table;
 import org.apache.ddlutils.platform.derby.DerbyPlatform;
 import org.apache.ddlutils.platform.hsqldb.HsqlDbPlatform;
+import org.apache.ddlutils.platform.mssql.MSSqlPlatform;
 import org.apache.ddlutils.platform.mysql.MySql50Platform;
 import org.apache.ddlutils.platform.mysql.MySqlPlatform;
 import org.apache.ddlutils.platform.postgresql.PostgreSqlPlatform;
@@ -1268,7 +1269,8 @@
         if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
             MySql50Platform.DATABASENAME.equals(getPlatform().getName()) ||
             PostgreSqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
-            DerbyPlatform.DATABASENAME.equals(getPlatform().getName()))
+            DerbyPlatform.DATABASENAME.equals(getPlatform().getName()) ||
+            MSSqlPlatform.DATABASENAME.equals(getPlatform().getName()))
         {
             query.append(" AS ");
             if (getPlatform().isDelimitedIdentifierModeOn())