RETURNING-Support in INSERT-Statements

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
wkupfer
Posts: 3
Joined: Tue 10 Oct 2006 09:33

RETURNING-Support in INSERT-Statements

Post by wkupfer » Tue 10 Oct 2006 09:49

Is IBDAC's TIBCQuery supporting the keyword RETURNING in INSERT-Statements?

Example:
The table T_EXAMPLE has the fields ID, LASTNAME, FIRSTNAME. ID is the primary key field. It is filled with a value from a generator G_EXAMPLE by a trigger (BEFORE INSERT).

The Statement

Code: Select all

INSERT INTO T_EXAMPLE (LASTNAME, FIRSTNAME)
VALUES (:LASTNAME, :FIRSTNAME)
RETURNING ID
returns the new ID value.

Is this proceeding possible with TIBCQuery?
Last edited by wkupfer on Tue 10 Oct 2006 10:40, edited 1 time in total.

Alex
Posts: 655
Joined: Mon 08 Nov 2004 08:39

Post by Alex » Tue 10 Oct 2006 10:16

We have implemented such functionality in the new version of IBDAC (IBDAC 2.00). It will be released in the near future.

wkupfer
Posts: 3
Joined: Tue 10 Oct 2006 09:33

How to get the new ID after insert?

Post by wkupfer » Wed 11 Oct 2006 08:22

Is there an alternative to get the new ID after an insert operation? I need this ID for additional inserts in detail tables.

xstef
Posts: 22
Joined: Sat 09 Sep 2006 20:44

Post by xstef » Wed 11 Oct 2006 10:13

There are 2 ways to do that

1) Use the KeyGenerator and KeyFields properties of IBCQuery. In that way depending on the GeneratorMode property you will have your ID filled with a value from the Generator either during Insert or Post.

2) Post the dataset so that your trigger fills the ID field and then call RefreshRecord to get all the values from the server.

Good luck,

Stefanos

TwinSoft

Alex
Posts: 655
Joined: Mon 08 Nov 2004 08:39

Post by Alex » Thu 12 Oct 2006 09:11

1) Use the KeyGenerator and KeyFields properties of IBCQuery. In that way depending on the GeneratorMode property you will have >your ID filled with a value from the Generator either during Insert or Post.
Also it is usefull to know that IBDAC internally uses RETURNING clause with generators in case of Firebird2 server connection and IBCQuery.GeneratorMode = gmPost. This allows to avoid unnecessary server roundtrip.
2) Post the dataset so that your trigger fills the ID field and then call RefreshRecord to get all the values from the server.
IBCQuery can do this refresh automatically, to enable this feature just include roAfterInsert in IBCQuery.RefreshOptions.

Post Reply