I am currently developing an iOS and Android app using PhoneGap. In my project, I am utilizing WebSql and encountering a certain issue: How can I rearrange the values in a column named 'position' when a row is deleted? For example, let's say we have the following base table:
╔═════╦══════════╗
║ ID ║ POSITION ║
╠═════╬══════════╣
║ 23 ║ 0 ║
║ 32 ║ 1 ║
║ 143 ║ 2 ║
║ 13 ║ 3 ║
╚═════╩══════════╝
If I were to delete the row with the position value of 1, the positions of the remaining rows should automatically decrement like so:
╔═════╦══════════╗
║ ID ║ POSITION ║
╠═════╬══════════╣
║ 23 ║ 0 ║
║ 143 ║ 1 ║
║ 13 ║ 2 ║
╚═════╩══════════╝
My question is: Is there a way to achieve this directly in MySql after deleting a row, or do I need to handle this logic in JavaScript by deleting the row, querying all the rows, looping through them to adjust their positions, and then updating the rows accordingly?
Any assistance on this matter would be greatly appreciated!