db-ddlutils-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vignesh Swaminathan" <vswam...@cordys.com>
Subject Update sql error in PostgreSQL 8.1
Date Thu, 16 Feb 2006 12:21:56 GMT
Hi,

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.



<vignesh/>
"Winning solutions find the right balance between market needs and
technical needs"


***************************************************************************************************
The information in this message is confidential and may be legally  privileged. 
It is intended solely for the addressee. Access to this message by anyone else is 
unauthorized. If you are not the intended recipient, any disclosure, copying, or 
distribution of the message, or any action or omission taken by you in reliance 
on it is prohibited and may be unlawful. Please immediately contact the sender if 
you have received this message in error. This email does not constitute any 
commitment  from Cordys Holding BV or any of its subsidiaries except when 
expressly agreed in a written agreement between the intended recipient and 
Cordys Holding BV or its subsidiaries.
 ***************************************************************************************************


Mime
View raw message