DBI question - last inserted id?

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

Nick Bicknell wrote:

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

Nick Bicknell wrote:

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

Hi,

is this portable to other db’s?

dbh.func(:insert_id)

till now i used

id = dbh.select_one(“SELECT LAST_INSERT_ID()”)

cheers
detlef

···

On Die, 2004-06-01 at 12:53 +0900, Paul Vudmaska wrote:

Wer für alles offen ist, kann nicht ganz dicht sein.

             <* ))))x<

Detlef Reichl wrote:

···

On Die, 2004-06-01 at 12:53 +0900, Paul Vudmaska wrote:

Nick Bicknell wrote:

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

Hi,

is this portable to other db’s?

dbh.func(:insert_id)

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