Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: DBI and last_insert_id

by graff (Chancellor)
on Jan 29, 2009 at 08:05 UTC ( [id://739815]=note: print w/replies, xml ) Need Help??


in reply to DBI and last_insert_id

Both previous replies are definitely on the mark. To follow up on the second one (and provide the missing detail that was not mentioned there): you want your "ON DUPLICATE KEY UPDATE ..." clause to include a reference to the primary key field -- something like this, assuming the "field_three" part is still needed:
. " ON DUPLICATE KEY" . " UPDATE field_three = ?, your_key_field=LAST_INSERT_ID(your +_key_field)";
I've always found this syntax to be a little disorienting, but you just have to accept the fact that when trying to insert a record that would violate some uniqueness constraint, the application of that constraint leaves the "last_insert_id" value "not meaningful". Check the last paragraph in section 12.2.4.3 of the mysql manual for an explanation (if you're using mysql), or the corresponding doc of your particular rdb server.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-26 04:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found