How to obtain an autogenerated field value

I'm using TRemoteDb, i'm facing this problem...

When i insert a new record, i use the OnRecordInsert event to send the sql code to the server side, and all is fine. I'm using Firebird on server .

But how can i have in return the refreshed record, with the ID (an autogenerated field value, the primary key of the table) which is automatically filled by the triggers / sequences of the db ? I need the ID value to create subsequently the "details" records, with a "IDPARENT" field filled with the ID generated.

Until now i've found only the possibility to query the db with a statement like

SELECT NEXT VALUE FOR <SequenceName> FROM RDB$DATABASE;

to

1) get the generated value prior to the insert operation,
2) assign the value to the ID field on client side
3) send the sql INSERT to the server side with the ID value already present

but maybe there is a better way...

Thanks

Arnaldo

I guess that is one of best approaches. You could also try to perform a select by a secondary unique index, if you have one.

Thank you Wagner, i think i will use my method, i have many tables with an ID "sequence-generated", and i need a "standard" approach that i can reuse.

Regards, ciao

Arnaldo