我需要找出记录是否存在,以便能够更新或删除它。
据我所知,一切都需要交易,选择计数是行不通的。
我几乎找不到任何有用的文档,我当前的代码是:
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);
}
});
任何帮助将不胜感激
您可以直接使用"更新"或"删除"
db.transaction(function(tx) {
tx.executeSql('UPDATE Category SET categoryName="' + categoryName
+ '",categoryIconPath="' + categoryIconPath
+ '",categoryDescription="' + categoryDescription
+ '" WHERE categoryId=' + categoryId + '', [], function(tx,
result) {
}, errorCB);
只需分别输入表名和列即可。这里的类别 ID 是唯一的,就像项目一样。您的案例中的身份证