MySQL Forums
Forum List  »  Newbie

batch update causes problems
Posted by: Jimi
Date: August 11, 2005 02:31PM

Hi

I have a table of images. Each image belongs to a certain imageAlbum, and each image has an index number and a filename.

Now I want the users to be able to change the index number for the images in his/her own imageAlbum. And everything works fine, down to the update batch. lets say one album looks like this:

imageAlbumId, filename, imageIndex
_____3______,img1.jpg,_____1_____
_____3______,img2.jpg,_____2_____
_____3______,img3.jpg,_____3_____
_____3______,img4.jpg,_____4_____

And lets say the user wants it to look like this instead:
_____3______,img4.jpg,_____1_____
_____3______,img1.jpg,_____2_____
_____3______,img2.jpg,_____3_____
_____3______,img3.jpg,_____4_____

The update is performed in a prepared statement (java), and for each change it does "UPDATE images SET imageIndex=? WHERE imageIndex=? AND albumId=?".

But when the first imageIndex is changed (1 -> 2) then the second change (2 -> 3) will change not only img2.jpg but also img1.jpg, because the current (new) index is infact 2. Is there a way to make the WHERE clause to use the OLD values? i.e the values from how the table looked BEFORE the first update.

/Jimi

Options: ReplyQuote


Subject
Written By
Posted
batch update causes problems
August 11, 2005 02:31PM


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.