Page 1 of 1

Batch Insert: How to get id's of inserted records?

Posted: Mon 17 Jul 2017 14:43
by tommy
For performance, I'd like to use either TUniLoader or a batch operation as described in 4.9 of the manual (array parameters).

However, for each record inserted I need its autoincrement ID as it will be used for reference in another table. Currently I iterate over setting parameters, executing and memorizing the LastInsertID which is not really performant.

How can I get the IDs of the inserted records with either TUniLoader or after an Execute(1000) statement?

Kinds regards,
Thomas

Re: Batch Insert: How to get id's of inserted records?

Posted: Tue 18 Jul 2017 12:20
by MaximG
Please specify what database you select when using our product. What do you think what result the Execute(1000) method should return?

Re: Batch Insert: How to get id's of inserted records?

Posted: Tue 18 Jul 2017 17:35
by tommy
Currently, I'm using an sqlite database, but I think this also applies to any other provider supporting the lastinsertid property.

After running Execute(1000) (or whatever number), I would expect to gain access to an array of all inserted IDs, analog to the ParamByName('xxx')[n] array which provides the data to be inserted. In other words, when using the Batch function, LastInsertID should be an array of INT64 instead of just an INT64.

Re: Batch Insert: How to get id's of inserted records?

Posted: Fri 21 Jul 2017 09:43
by MaximG
Unfortunately, in this question, we are limited by the possibilities of SQLite, which provides only the last_insert_rowid function (http://www.sqlite.org/c3ref/last_insert_rowid.html) to return values of interest to you. This function allows you to return a value for only one inserted record. If there is the necessary support from the server in the database (for example, Oracle DB), then we return the autoincrement values as an array (this is the behavior that is implemented in our ODAC product).

Re: Batch Insert: How to get id's of inserted records?

Posted: Tue 25 Jul 2017 15:36
by tommy
Ok, I understand. Thanks for your explanation.

Re: Batch Insert: How to get id's of inserted records?

Posted: Thu 27 Jul 2017 12:07
by MaximG
Thank you for your interest to our products. Feel free to contact us if you have any further
questions about UniDAC.