<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>CodingClues - Latest Comments in Preventing Database Race Conditions</title><link>http://codingclues.disqus.com/</link><description></description><atom:link href="http://codingclues.disqus.com/preventing_database_race_conditions/latest.rss" rel="self"></atom:link><language>en</language><lastBuildDate>Tue, 30 Sep 2008 05:51:57 -0000</lastBuildDate><item><title>Re: Preventing Database Race Conditions</title><link>http://codingclues.eu/2008/preventing-database-race-conditions/#comment-3855797</link><description>&lt;p&gt;yeah all this should be no big deal when you are using mysql 5 w/ transactions (which i'm not and was not refering to in this article)&lt;br&gt;thx&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Tobias</dc:creator><pubDate>Tue, 30 Sep 2008 05:51:57 -0000</pubDate></item><item><title>Re: Preventing Database Race Conditions</title><link>http://codingclues.eu/2008/preventing-database-race-conditions/#comment-3855794</link><description>&lt;p&gt;When your racing inserts are not using the same DB connection then at least mysql_insert_id() will work, as that is just a wrapper to a C API call and said call is "client-connection-aware".&lt;br&gt; I am not sure about the SELECT LAST_INSERT_ID though, that might actually be a problem (if not client-connection-aware), although inside of a transaction it should work even with concurrent inserts from other threads.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">lino</dc:creator><pubDate>Tue, 30 Sep 2008 05:34:51 -0000</pubDate></item><item><title>Re: Preventing Database Race Conditions</title><link>http://codingclues.eu/2008/preventing-database-race-conditions/#comment-3855795</link><description>&lt;p&gt;thanks, never heared of this LAST_INSERT_ID statement before&lt;br&gt;I had abstracted from the actual PHP code in this example (therefore no identifier)&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Tobias</dc:creator><pubDate>Tue, 30 Sep 2008 05:16:01 -0000</pubDate></item><item><title>Re: Preventing Database Race Conditions</title><link>http://codingclues.eu/2008/preventing-database-race-conditions/#comment-3855796</link><description>&lt;p&gt;I already pointed that out to Tobias.&lt;/p&gt;

&lt;p&gt;However, the problem is, when you have e.g. 2 racing inserts, you only get the last ID of the two, but not the last two IDs. For Tobias' application, he needed exactly the one ID that he used in his INSERT, not the last one.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Sebastian</dc:creator><pubDate>Tue, 30 Sep 2008 05:14:51 -0000</pubDate></item><item><title>Re: Preventing Database Race Conditions</title><link>http://codingclues.eu/2008/preventing-database-race-conditions/#comment-3855798</link><description>&lt;p&gt;While your solution might work, mysql_insert_id() or, if you are using a BIGINT as auto_increment mysql_query('SELECT LAST_INSERT_ID() FROM table') is the better solution. Don't forget to pass the resource_identifier of your mysql connection. And I ideally, if you are using MySQL 5, encapsulate the whole operation into a transaction.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">lino</dc:creator><pubDate>Tue, 30 Sep 2008 04:38:17 -0000</pubDate></item></channel></rss>
