Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: Getting ID of last row inserted into database

by VSarkiss (Monsignor)
on Jan 25, 2006 at 20:24 UTC ( #525563=note: print w/ replies, xml ) Need Help??


in reply to Re: Getting ID of last row inserted into database
in thread Getting ID of last row inserted into database

Indeed. I just want to point (for the OP) that support for last_insert_id varies greatly from DBMS to DBMS, and not all DBD's implement it in a reasonable way. Caveat selector.


Comment on Re^2: Getting ID of last row inserted into database
Download Code
Re^3: Getting ID of last row inserted into database
by lima1 (Curate) on Jan 25, 2006 at 21:04 UTC
    yes...had some problems with that, but with this parameter combination:
    $self->db->dbh->last_insert_id(undef, undef, 'tablename', 'id_name');
    SQLite, MySQL 4.0 and PostgreSQL 8.1 all pass my tests. I think SERIAL UNIQUE NOT NULL was also necessary for Pg, but not sure.
Re^3: Getting ID of last row inserted into database
by Yendor (Pilgrim) on Jan 26, 2006 at 15:20 UTC

    Aye. Reading the DBI docs that Corion pointed me to were a great help. I ended up with the following as my call to last_insert_id:

    my $LastID = $dbh->last_insert_id(undef, 'public', 'CUSTOMER_INFORMATION', 'ID');

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://525563]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2014-11-26 23:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (176 votes), past polls