DBI question - last inserted id?

N

Nick Bicknell

Hi,

For the Ruby DBI experts out there...

I'm using Ruby DBI and MySQL and I'm wondering if there's a method that I'm missing that will yield the last inserted id for a given table after issuing an insert. In the Perl DBI, there's a way to get it with $sth->{mysql_insertid}. Is there something in Ruby DBI that is equivalent?

Thanks,
Nick
 
P

Paul Vudmaska

Nick said:
Hi,

For the Ruby DBI experts out there...

I'm using Ruby DBI and MySQL and I'm wondering if there's a method that I'm missing that will yield the last inserted id for a given table after issuing an insert. In the Perl DBI, there's a way to get it with $sth->{mysql_insertid}. Is there something in Ruby DBI that is equivalent?

Thanks,
Nick
dbh.func:)insert_id)

Here is a nice resource.
http://www.kitebird.com/articles/ruby-dbi.html
Paul
 
P

Paul Vudmaska

Detlef said:
Hi,

is this portable to other db's?




till now i used

id = dbh.select_one("SELECT LAST_INSERT_ID()")

cheers
detlef
Actually, no. In postegre you must run sql to get the last id much as
you do above(but different :)).
:paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top