I want to create and maintain an SQLite database which mirrors the content of an NSMutableArray. To do so I obviously need to keep track of the array index corresponding to each database entry, and it seems to me (as someone who knows relatively little about SQLite) that using the rowid column is a good way to do so.
When an object is inserted in the middle of the array, I need to update the database by incrementing the rowid column for all entries after the insertion point, before I can insert the new entry. For example:
UPDATE table SET rowid = rowid + 1 WHERE rowid >= 5;
This returns an error, as is to be expected: when the first rowid is incremented, it immediately conflicts with the next rowid.
What I can't figure out for the life of me is whether there is a way around this problem. Common sense would suggest that there is - all I really need to do is to increment the rowid column in reverse order, but I can't find any way to do so.
Online documentation for SQLite, both official and unofficial, seems quite poor. Can anybody point me in the right direction?
When an object is inserted in the middle of the array, I need to update the database by incrementing the rowid column for all entries after the insertion point, before I can insert the new entry. For example:
UPDATE table SET rowid = rowid + 1 WHERE rowid >= 5;
This returns an error, as is to be expected: when the first rowid is incremented, it immediately conflicts with the next rowid.
What I can't figure out for the life of me is whether there is a way around this problem. Common sense would suggest that there is - all I really need to do is to increment the rowid column in reverse order, but I can't find any way to do so.
Online documentation for SQLite, both official and unofficial, seems quite poor. Can anybody point me in the right direction?