note 54274 added to function.mysql-affected-rows

From: Date: Wed, 29 Jun 2005 12:39:43 +0000
Subject: note 54274 added to function.mysql-affected-rows
Groups: php.notes 
Request: Send a blank email to php-notes+get-91129@lists.php.net to get a copy of this message
SCENARIO 1. You're using MySQL 4.1x with foreign keys. 2. You have table t2 linked to table t1 by a CASCADE ON DELETE foreign key. 3. t2 has a UNIQUE key so that duplicate records are unacceptable. 3. You have a REPLACE query on t1 followed by an INSERT query on t2 and expect the second query to fail if there's an attempted insert of a duplicate record. PROBLEM You notice that the second query is not failing as you had expected even though the record being inserted is an exact duplicate of a record previously inserted. CAUSE When the first query (the REPLACE query) deletes a record from t1 in the first stage of the REPLACE operation, it cascades the delete to the record that would be duplicated in t2. The second query then does not fail because the "duplicate" record is no longer a duplicate, as the original one has just been deleted. ---- Manual Page -- http://www.php.net/manual/en/function.mysql-affected-rows.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54274 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54274&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54274&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54274&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54274&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54274&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54274&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54274&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#91129) next »