How to Getting RETURNING value from INSERT INTO

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
xspower
Posts: 1
Joined: Wed 18 Jul 2018 04:00

How to Getting RETURNING value from INSERT INTO

Post by xspower » Wed 18 Jul 2018 04:02

I need some help with my problem. I'm trying to get the "RETURNING" value from an INSERT INTO statement, but I can't seem to get it right. I read up the documentation, but couldn't solve the problem based on it... (the info is very vague, for me at least)

I'm using Firebird 2.0 with Delphi 7 and IBDAC 2.0 BTW.

Here is an example query:

(note: RowID is an automatically generated value)

Main.DBQuery.DMLRefresh:=true;
Main.DBQuery.SQL.Text:='INSERT INTO Table(RowID, RowData)
VALUES(NULL, :rd) RETURNING RowID';
Main.DBQuery.ParamByName('rd').AsString:="Example Data";
Main.DBQuery.ExecSQL;

Tag:=Main.DBQuery.FieldByName('RET_RowID').AsInteger;

The result:

RET_RowID isn't found.

I've also tried using

Tag:=Main.DBQuery.Fields[0].AsInteger;

But that doesn't work either.

As it seems the me, the returned value is not returned as a field.
If so, how can I read it out?

Could you please give me actual example code I can use?

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: How to Getting RETURNING value from INSERT INTO

Post by ViktorV » Wed 18 Jul 2018 06:12

For the fields, that are specified after RETURNING, there are automatically generated output parameters with the RET_ prefix. This is described in the documentation: https://www.devart.com/ibdac/docs/index ... ataset.htm
To get the OUT parameter value, use the following code:

Code: Select all

ShowMessage(UniQuery.ParamByName('RET_RowID').AsString);

Post Reply