tgh003@gmail.com wrote:
[color=blue]
> Yes i know about ORDER BY. That is not the issue.
>
> When displayed using a UI, i want the user to be able to reorder the
> list by moving a task up or down based on priority.
>
> I then need to save those changes to the database, and in order to do
> this i would need to reupdate all the records. This is obviously not
> very scalable/efficient to do this everytime there is a change assuming
> the task list is long.
>
> any other ideas?[/color]
How many items? If a dozen, even a hundred, an update to the entire table
is sub-second. Of course I will deny ever having made the suggestion if
you run into any trouble.
How many columns in the table? Another strategy is to directly swap the
values of all columns except "sort" in a single transaction:
begin transaction
update priorities set id=ValFromRow15,task=ValfromRow15 where sort=3
update priorities set id=ValFromRow3,task=ValfromRow3 where sort=15
commit
You may have trouble with ID, hmmm. What is that column doing anyway?
It also seems you may want the client to force only certain types of moves
so you don't have a big jumble to sort out when you try to commit. Perhaps
allow the user to adjust the priority of only one row at a time before a
trip to the server, so at most you are only ever swapping two rows.
--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)