Welcome Guest, Not a member yet? Register   Sign In
How to get id after insert data
#11

[eluser]WanWizard[/eluser]
It shouldn't happen that two processes that insert a record in the same table get the same id.

The database engine makes sure all inserts with auto_increment columns are atomic, you can't have two records with the same id (you probably have that field as primary index, so the second insert would abort with a duplicate key error anyway).

The insert_id field is a property of the connection, even if you work with pooled connections only one process is ever using a connection at any given time.

Offcourse, when you think you can outsmart the database engine and try to use your own logic to determine the insert id (like suggested above), you will have to use multiple queries, which severly increases that chance that another process inserts the record you're process thinks it's inserting. To do this safe, you would need a write lock on the table during your transaction, something to avoid at all costs if you value the performance of your application.


Messages In This Thread
How to get id after insert data - by El Forum - 07-19-2009, 02:39 AM
How to get id after insert data - by El Forum - 07-19-2009, 03:19 AM
How to get id after insert data - by El Forum - 07-19-2009, 04:11 AM
How to get id after insert data - by El Forum - 07-19-2009, 04:56 AM
How to get id after insert data - by El Forum - 07-19-2009, 06:39 AM
How to get id after insert data - by El Forum - 07-19-2009, 10:05 AM
How to get id after insert data - by El Forum - 07-19-2009, 11:32 AM
How to get id after insert data - by El Forum - 07-19-2009, 11:42 AM
How to get id after insert data - by El Forum - 09-11-2010, 02:21 PM
How to get id after insert data - by El Forum - 09-11-2010, 02:52 PM
How to get id after insert data - by El Forum - 09-11-2010, 03:26 PM
How to get id after insert data - by El Forum - 09-11-2010, 03:29 PM
How to get id after insert data - by El Forum - 09-12-2010, 02:09 AM
How to get id after insert data - by El Forum - 09-12-2010, 04:20 AM



Theme © iAndrew 2016 - Forum software by © MyBB