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 @@
/**
* [EMAIL PROTECTED]
+ * 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;
}
/**