db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject svn commit: r372576 - /db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlBuilder.java
Date Thu, 26 Jan 2006 17:37:31 GMT
Author: mvdb
Date: Thu Jan 26 09:37:28 2006
New Revision: 372576

URL: http://svn.apache.org/viewcvs?rev=372576&view=rev
Log:
Fixed errors when inserting data in a table with an autoincrement primary field.
Normally mysql will return the LAST_INSERT_ID as the column name for the inserted id. Since
ddlutils expects the real column name of the field that is autoincrementing, the column has
an alias of that column name.

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlBuilder.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlBuilder.java?rev=372576&r1=372575&r2=372576&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlBuilder.java Thu Jan
26 09:37:28 2006
@@ -76,10 +76,18 @@
 
     /**
      * {@inheritDoc}
+     * Normally mysql will return the LAST_INSERT_ID as the column name for the inserted
id.
+     * Since ddlutils expects the real column name of the field that is autoincrementing,
the
+     * column has an alias of that column name.
      */
     public String getSelectLastInsertId(Table table)
     {
-        return "SELECT LAST_INSERT_ID()";
+        String autoIncrementKeyName = "";
+        if (table.getAutoIncrementColumns().length > 0)
+        {
+            autoIncrementKeyName = table.getAutoIncrementColumns()[0].getName();
+        }
+        return "SELECT LAST_INSERT_ID() " + autoIncrementKeyName;
     }
 
     /**



Mime
View raw message