empire-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rainer Döbele <doeb...@esteam.de>
Subject re: DbRecord.update() without prior reading the record
Date Fri, 17 May 2013 12:44:49 GMT
Hi Harald,

with a DBCommand you can do anything that you would be able to do by simply typing your statement.

DBCommand cmd = db.createCommand();
db.executeUpdate(cmd, conn);

A DBRecord uses a DBCommand internally but provides more features to handle inserts and updates.
Normally you will have to read the record before you can perform an update.
If you want it differenty you will have to subclass DBRecord and change a few things.
(call initData() and then modifyValue() to set the PK).
But this is more complicated.


> from: Harald Kirsch [mailto:Harald.Kirsch@raytion.com]
> to: user@empire-db.apache.org
> re: DbRecord.update() without prior reading the record
> Hi,
> I have a table that has a surrogate, autoincremented primary key, a unique
> key from the modeled domain and some data columns, like
> ID - INTEGER, primary
> name, CHAR(10), unique
> info, TEXT, NotNull
> completed, BOOL
> At some point in the program I know the name and I would like to update the
> completed column. I thought to use something like
> DBRecord rec = new DBRecord();
> dbrecord.create(myTable);
> dbrecord.setValue(nameColumn, name);
> dbrecord.setValue(completed, true);
> rec.update()
> This throws an exception complaining about info not allowed to be null.
> Looking at the source code of empire db it seems like I just can't use it for an
> update without the primary key.
> Is there another way of directly updating a column by using select, without
> first reading the record and then changing it. I see that DBCommand has a
> getUpdate(), but I don't see how to set the columns values to update?
> Thanks,
> Harald.
> --
> Harald Kirsch
> Raytion GmbH
> Kaiser-Friedrich-Ring 74
> 40547 Duesseldorf
> Fon +49-211-550266-0
> Fax +49-211-550266-19
> http://www.raytion.com

View raw message