in reply to Re: last_insert_id() in sybase
in thread last_insert_id() in sybase
If I recall correctly, when I used Sybase (about 12 years ago) I used to do it like this:
my $SQL = <<EOSQL; begin insert into foo (col1, uniquecol) values (?, ?); select id from foo where uniquecol=?; end EOSQL my $ST = $DB->prepare($SQL); $ST->execute('abacus', 'S/N5842', 'S/N5842'); while (my $hr = $ST->fetchrow_hasharray) { print "ID is $$hr{ID}\n"; }
Since it's executed in a transaction, there isn't a race condition. However, you *do* need to be able to uniquely identify the row without using it's ID--by using a unique (group of) column(s).
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
---|