Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Getting ID of last row inserted into database

by saberworks (Curate)
on Jan 25, 2006 at 20:21 UTC ( [id://525562]=note: print w/replies, xml ) Need Help??


in reply to Getting ID of last row inserted into database

Also, your select of the MAX(id) is subject to a race condition - if another user does an insert between the time you insert and you fetch the id, you will get their ID (probably not what you want). The DBI functions should be associated with your statement handles, so you shouldn't have that problem.
  • Comment on Re: Getting ID of last row inserted into database

Replies are listed 'Best First'.
Re^2: Getting ID of last row inserted into database
by Yendor (Pilgrim) on Jan 26, 2006 at 15:15 UTC

    Right.

    That's an understood part of the problem, and also why my "select" solution felt like such a hack. I did my best to mitigate it by adding the FirstName/LastName to the WHERE clause when selecting the ID I was looking for.

    At that point, the only race condition problem would have been on someone inserting the same data multiple times during the (acknowledged) race condition period.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-24 12:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found