Page 1 of 1

How to Getting RETURNING value from INSERT INTO

Posted: Wed 18 Jul 2018 04:02
by xspower
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?

Re: How to Getting RETURNING value from INSERT INTO

Posted: Wed 18 Jul 2018 06:12
by ViktorV
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);