Reputation: 881
I am needing to find out if a record exists, so that I am able to update or delete it.
Seeing as to the best of my knowledge, everything required a transaction, selecting a count will not work.
There is hardly any documentation I can find that is usefull, the current code i have is:
app.database.db.transaction(function (tx) {
$.each(result.specoffer, function (i, item) {
if (typeof item.id != 'undefined') {
var sql = '' +
'IF EXISTS SELECT id FROM Specials WHERE id = ' + item.id + ' ' +
'UPDATE Specials SET picture = "' + item.picture + '", startdate = "test", finishdate = "test", mess = "' + item.mess + '", shortmess = "' + item.picture +
'", shortmess = "' + item.shortmess + '", name = "' + name + '" WHERE id = ' + item.id + ' ' +
'ELSE ' +
'INSERT INTO Specials (id, picture, startdate, finishdate, mess, shortmess, name) VALUES (' +
item.id + ', "' + item.picture + '", "test", "test", "' + item.mess + '", "' + item.shortmess + '", "' + item.name + '")';
tx.executeSql(sql);
}
});
Any help would be much appreciated
Upvotes: 0
Views: 211
Reputation: 544
You can use Update or Delete directly
db.transaction(function(tx) {
tx.executeSql('UPDATE Category SET categoryName="' + categoryName
+ '",categoryIconPath="' + categoryIconPath
+ '",categoryDescription="' + categoryDescription
+ '" WHERE categoryId=' + categoryId + '', [], function(tx,
result) {
}, errorCB);
Just put your table name and columns respectively. Here categoryId is unique like item.Id in your case
Upvotes: 1