node-db-oracle icon indicating copy to clipboard operation
node-db-oracle copied to clipboard

Get last insert id via a returning statement

Open joeferner opened this issue 13 years ago • 1 comments

I'm working on an ORM framework for node.js (https://github.com/nearinfinity/node-persist/) and I need a way to get the last inserted id. I have a table Person with columns id, name, age. The id column is associated with a sequence via a before insert trigger. I would like to get the id out when I execute the following sequence.

INSERT INTO Person (name, age) VALUES ('bob', 23) RETURNING id INTO ?

I would love to use your oracle driver but it doesn't look like there is any way to bind out parameters via the execute command.

I have a branch here: https://github.com/nearinfinity/node-persist/tree/db-oracle which is the start of incorporating your driver but if you run the nodeunit tests on select.js you will see I cannot get the id column back out.

joeferner avatar Dec 16 '11 22:12 joeferner

I found an example of someone doing this in perl (http://www.unix.com/shell-programming-scripting/59764-perl-oracle-bind_param_inout.html) with the api docs here (http://search.cpan.org/~timb/DBI/DBI.pm#bind_param_inout).

joeferner avatar Dec 17 '11 05:12 joeferner