db-ddlutils-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Dudziak <tom...@gmail.com>
Subject Re: Update sql error in PostgreSQL 8.1
Date Thu, 16 Feb 2006 12:45:22 GMT
On 2/16/06, Vignesh Swaminathan <vswamina@cordys.com> wrote:

> Tried update this time and had an exception thrown, the code is
>
> iter = testData.query("select * from orders", new ArrayList());
> while(iter.hasNext())
> {
>    order = (DynaBean)iter.next();
>
>    System.out.println(order.get("id"));
>    System.out.println(order.get("shipdate"));
> }
>
> DynaBean bean = testData.getDynaBean("orders");
> bean.set("id", order.get("id"));
> bean.set("customerid", new Integer(2312));
> bean.set("orderdate", order.get("orderdate"));
> bean.set("shipdate", order.get("shipdate"));
> System.out.println(platform.getUpdateSql(dbModel, (SqlDynaBean) bean));
> platform.update(dbModel, bean);
>
> The exception is
>
> org.apache.ddlutils.DynaSqlException: Error while updating in the
> database
>         at
> org.apache.ddlutils.platform.PlatformImplBase.update(PlatformImplBase.ja
> va:1352)
>         at
> org.apache.ddlutils.platform.PlatformImplBase.update(PlatformImplBase.ja
> va:1369)
>         at TestData.updateData(TestData.java:73)
>         at TestData.main(TestData.java:151)
> Caused by: org.postgresql.util.PSQLException: The column index is out of
> range: 4, number of columns: 3.
>         at
> org.postgresql.core.v3.SimpleParameterList.bind(SimpleParameterList.java
> :57)
>         at
> org.postgresql.core.v3.SimpleParameterList.setLiteralParameter(SimplePar
> ameterList.java:101)
>         at
> org.postgresql.jdbc2.AbstractJdbc2Statement.bindLiteral(AbstractJdbc2Sta
> tement.java:2066)
>         at
> org.postgresql.jdbc2.AbstractJdbc2Statement.setInt(AbstractJdbc2Statemen
> t.java:1114)
>         at
> org.apache.ddlutils.platform.PlatformImplBase.setObject(PlatformImplBase
> .java:1682)
>         at
> org.apache.ddlutils.platform.postgresql.PostgreSqlPlatform.setObject(Pos
> tgreSqlPlatform.java:237)
>         at
> org.apache.ddlutils.platform.PlatformImplBase.update(PlatformImplBase.ja
> va:1338)
>         ... 3 more
>
> The SQL generated from getUpdateSql is
>
> UPDATE "orders" SET "customerid" = '1000', "orderdate" = '2006-03-16
> 00:00:00.0', "shipdate" = '2006-04-21 00:00:00.0' WHERE
>
> As you can see the statement is not completed. Debugged to find that the
> method createUpdateSql in PlatformImplBase sends only the non primary
> key properties to method getUpdateSql in SQLBuilder class. This causes
> the WHERE statement to be empty as an if check fails at
>
> if (column.isPrimaryKey() && columnValues.containsKey(column.getName()))
>
> As the primary key column is not in the columnValues Map, leaving an
> empty WHERE clause string.

Could you file an issue for this ?

Tom

Mime
View raw message