Hi Denis,

UpdatableRecord currently doesn't have an "UPSERT" feature (or INSERT ON
DUPLICATE KEY UPDATE, etc.) This is a pending feature request:
https://github.com/jOOQ/jOOQ/issues/2961

I guess we've postponed it long enough now, it shouldn't be too hard to
implement...
In the meantime, you can pass your record to an actual INSERT ON DUPLICATE
KEY UPDATE statement:

ctx.insertInto(MYTABLE)
   .set(rec)
   .onDuplicateKeyUpdate()
   .set(rec) // Maybe manually reset the PK columns again, here...
   .execute();


Hope this helps,
Lukas

2016-10-22 16:05 GMT+02:00 Denis Miorandi <[email protected]>:

> I'm trying to use UpdatableRecord store() method, but it's not clear to me
> the right way.
> In my scenario I would like
>
>    - create a record in memory, so
>    - store record wheter exists or not so )
>
> rec=ctx.newRecord(MYTABLE)
> rec.setField1(1)
> rec.setField2(1)
> ....
> rec.store()
>
> Issue is store() try to always insert it (wheter exists or not on db)
> cause not loaded from db with rec.refresh(),
> so that I've tried to do same thing using a refresh on rec (after set keys
> before set other values) but refresh()
> fail is record doesn't exists. So:
>
>
>    - refresh() works only on existings records
>    - store() works only if a record is loaded from refresh() otherwise
>    always insert
>
> Am I right? Am I missunderstanding something?
> How can I store a new record wheter exists or not on db?
>
> Tks
> Denis
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "jOOQ User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to