WebDb update problem
i have this code for my webdb, i try to delete an item and set the order to the other one, but it change only the last item.
for (var i=ordine2; i < lunghezza-1+ordine2; i++) {
var db = miodb.webdb.db;
var ordine3=ordine2+i+1;
var ordine4=ordine2+i;
db.transaction(function(tx){
tx.executeSql("UPDATE todo SET ordine = " + "'" + ordine4 + "'" + " WHERE ordine=?", [ordine3],
miodb.webdb.onSuccess,
miodb.webdb.onError);
});
}
this is my table: id | content | order
1 | 0 | 0 |
2 | 1 | 1 |
3 | 2 | 2 |
4 | 3 | 3 |
5 | 4 | 4 |
6 | 5 | 5 |
If i delete the first item i wants that all the other it开发者_开发百科em change the order to current order -1, but it doesn't works, only the last item change the order, ordine2 is set to 0, lunghezza is the length of array. Who can i fix it?
You don't need a loop for this at all. What about the following update statment?
UPDATE todo SET ordine = ordine - 1
You might need to add an appropriate where clause on that, some thing like "WHERE ordine > ordine2". I don't fully understand what it is you're trying to do so I can't give you the exact code.
Also, you really shouldn't be using string concatenation at all in building your SQL statement, use a ? for every parameter and put them in the array as you did for ordine3, that way you know they'll be properly escaped.
精彩评论