Bug 125 : Change the SQL statement on a SqlUpdate multiple times...
Priority 
High
Reported Version 
 
Logged By 
Rob
Status 
Fixed
Fixed Version 
2.0.0
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
18/06/2009
Updated 
18/06/2009
Type 
Bug
 
Attachments 
No attachments

If you get a SqlUpdate and change set its SQL more than once it can use the wrong sql.

That is, SqlUpdate is designed around using a single SQL statement ... but the api allows you to change the SQL and hence use it in a way not intented.

SqlUpdate sqlUpdate = Ebean.createSqlUpdate();
sqlUpdate.setSql("insert into mytable ... ");
sqlUpdate.setParameter(...)
sqlUpdate.setParameter(...)
sqlUpdate.execute();

sqlUpdate.setSql("insert into anothertable");
sqlUpdate.setParameter(...)
sqlUpdate.setParameter(...)
sqlUpdate.execute();

 
Rob 18 Jun 02:40
Change of API suggestion

Suggestion from Eddie:

...we can just pass the sql to the create method

SqlUpdate update = ebeanServer.createSqlUpdate("Insert into Person...");

... and remove the setSql() method.

Will break some code but then you don't have this problem anymore and an update's sql is immutable.

Rob 18 Jun 02:42
Makes sense ... perhaps have

Makes sense... the only problem is that would clash with the existing "named" update method.

However, long term your suggestion sounds a lot better to me... hmmm ...

... could perhaps change it to:

createNamedSqlUpdate(String)
createSqlUpdate(String)

... and do the same for the SqlQuery side:

createNamedSqlQuery(String)
createSqlQuery(String)


Certainly makes more sense than the current api. Hopefully we wouldn't be breaking too much existing code.

woResponse

Upload a file