Well, here is my decision to make programming easier for those who are going on with this thread. The trick can update all order indices above or below insert / delete in one update.
Using a numeric (integer) column in your table supported by SQL queries
CREATE TABLE myitems (Myitem TEXT, id INTEGER PRIMARY KEY, orderindex NUMERIC);
To remove an item in orderindex 6:
DELETE FROM myitems WHERE orderindex=6; UPDATE myitems SET orderindex = (orderindex - 1) WHERE orderindex > 6;
To swap two items (4 and 7):
UPDATE myitems SET orderindex = 0 WHERE orderindex = 4; UPDATE myitems SET orderindex = 4 WHERE orderindex = 7; UPDATE myitems SET orderindex = 7 WHERE orderindex = 0;
i.e. 0 is not used, so use it as a mannequin to avoid an ambiguous element.
Paste in 3:
UPDATE myitems SET orderindex = (orderindex + 1) WHERE orderindex > 2; INSERT INTO myitems (Myitem,orderindex) values ("MytxtitemHere",3)
Kickaha Apr 27 '12 at 19:26 2012-04-27 19:26
source share