Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

by VSarkiss (Monsignor)
on Jan 25, 2006 at 20:24 UTC ( [id://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.

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://525563]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-19 14:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found