MySQL Forums
Forum List  »  General

Update disobeying where clause
Posted by: Rylee Isitt
Date: December 10, 2005 01:53AM

I have never seen this before, and am completely at a loss... hopefully someone here can help me.

I have this update query (copied exactly as used in my application):
UPDATE tblContent SET lft=lft-2, rgt=rgt-2 WHERE lft >= 60 AND rgt <= 61

Applied to this data

tblContent:
contentID lft rgt
42 56 57
43 58 59
44 60 61

Results in this:

tblContent:
contentID lft rgt
42 56 57
43 56 57
44 56 57

Note how not only did the UPDATE touch more rows than it should have, but the resulting lft and rgt values of contentID 44 are incorrect as well. The result should have been:

tblContent:
contentID lft rgt
42 56 57
43 58 59
44 58 59

Now some background.
This occurs using both MyISAM and InnoDB. All queries are going through a function that prevents injections (it escapes certain characters in variables/user input), but the query I've pasted in this message is the function's output so you can see that it doesn't contain any oddities (not any that are obvious to me, anyway).

Here is a list of queries occuring before and after the update in question:
1. LOCK TABLES tblContent WRITE
2. SELECT lft, rgt FROM tblContent WHERE contentID = '44'
3. SELECT lft, rgt FROM tblContent WHERE contentID = '43'
4. UPDATE tblContent SET lft=lft-2, rgt=rgt-2 WHERE lft >= 60 AND rgt <= 61
5. UNLOCK TABLES

Running this in Win XP Pro, Apache 2.0.53, PHP 5.0.4, MySQL 4.1.10-nt

Options: ReplyQuote


Subject
Written By
Posted
Update disobeying where clause
December 10, 2005 01:53AM
December 10, 2005 02:33AM
December 10, 2005 12:07PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.