mardi 21 juillet 2015

Update Sqlite column to remove missing numbers

I have an Sqlite table that has a column for play_order.
If I delete an item is there a command to reorder the data to remove the now missing number from the column?

For example, say the table looks like this:

_id | play_order
----------------
1   | 0
2   | 1
3   | 2
4   | 3
5   | 4

I delete _id 3, I'd like to reorder the play_order so _id 4 now has a play_order of 2 and _id 5 has 3 etc...

I can do this in Java (Android), but would rather do it in SQL if possible.

I've tried using a fake row id, but the data is all over the table and can be full of other random data at any point.

I've also thought of doing a subquery and getting all the data, but don't know if I can loop over it or something to set the the order.

As far as Android goes, I've looked into doing a "applybatch" on the contentresolver, but can't get that to work either.

Aucun commentaire:

Enregistrer un commentaire