lbehnke / h2database

Automatically exported from code.google.com/p/h2database
0 stars 0 forks source link

JaQu: simple update and merge methods #121

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The following patch adds two simple methods update(Object) and
merge(Object) to the JaQu Db class, complementary to the existing
insert(Object) method.

Both methods require that one or more primary key columns are defined on
the table class. Otherwise an exception is thrown.

Db.update(Object) issues a statement like "UPDATE table SET col1 = ?, col2
= ?, ... WHERE pk1 = ?, pk2 = ?, ..."

Db.merge(Object) issues a statement like "MERGE INTO table (pk1, pk2, ...,
col1, col2, ...) KEY(pk1, pk2, ...) VALUES(?,?,?,...)"

What version of the product are you using? On what operating system, file
system, and virtual machine?

rev. 1857
Windows XP
JDK 1.5.0.14

How important/urgent is the problem for you?

nice to have

In your view, is this a defect or a feature request?

enhancement

Please provide any additional information below.

If I find the time, I plan to provide a patch for update...where semantics
as well. Proposal:

db.from(p).set(p.unitsInStock).to(10).where(p.productName).is("Chang").update();

Original issue reported on code.google.com by dmoeb...@gmx.net on 21 Sep 2009 at 1:08

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks a lot! That's great. I only had to change the error message format (a 
space
was missing).

> patch for update...where semantics

I'm not sure about that, how do you plan to support updating multiple columns?

Original comment by thomas.t...@gmail.com on 22 Sep 2009 at 7:27

GoogleCodeExporter commented 9 years ago
db.from(p)
  .set(p.unitsInStock).to(10)
  .set(p.unitPrice).to(123.4)
  .where(p.productName).is("Chang")
  .update();

I'm not sure if this works, just thinking out loud.

Thanks for applying the patch! :-)

Original comment by dmoeb...@gmx.net on 22 Sep 2009 at 7:32

GoogleCodeExporter commented 9 years ago
I like your proposal. Another idea is using something similar to the existing
select(new Object()) syntax:

db.from(c).
  where(p.productName).is("Chang").
  update(new Prouct() {{
    unitsInStock = 10;
    unitPrice = 123.4;
  }});

Original comment by thomas.t...@gmail.com on 25 Sep 2009 at 3:43

GoogleCodeExporter commented 9 years ago
The patch for merge and update is included in version 1.1.119

Original comment by thomas.t...@gmail.com on 26 Sep 2009 at 11:34

GoogleCodeExporter commented 9 years ago
Thanks for including my patches. :-)

Your proposal is better than mine because the compiler checks the value 
assignments.

Original comment by dmoeb...@gmx.net on 27 Sep 2009 at 8:23