lundi 31 août 2015

SQLite trigger for maintaining a "position" column

I have a need to maintain a "position" column in one of my tables.

Database Table Example

If row 1 (id = 1) is moved down to position 3 (id = 4) I need to update row (id = 1) with position value of 3, but then I would need to increment all of the rows with a position < 3 down by 1. This would also apply for the opposite, except the position would be incremented up by 1. How could I write a trigger to do this logic for me when the position column is updated?

Aucun commentaire:

Enregistrer un commentaire