Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 在phonegap中插入重复键_Sql_Sqlite_Cordova - Fatal编程技术网

Sql 在phonegap中插入重复键

Sql 在phonegap中插入重复键,sql,sqlite,cordova,Sql,Sqlite,Cordova,在MySQL中,有什么东西可以作为重复键插入SQLite吗 在PhoneGap中,我在“on replicate”上得到一个SQL语法错误。我不想在插入前查找每个项目 我的代码: $.each(jsondata, function(i, item) { tx.executeSql('INSERT INTO Pricelist2 (id, name,desc,make,price) '+ 'VALUES ('+jsondata[i].id+', '+

在MySQL中,有什么东西可以作为重复键插入SQLite吗

在PhoneGap中,我在“on replicate”上得到一个SQL语法错误。我不想在插入前查找每个项目

我的代码:

$.each(jsondata, function(i, item) {
    tx.executeSql('INSERT INTO Pricelist2 (id, name,desc,make,price) '+
                  'VALUES ('+jsondata[i].id+', '+
                           '"'+data[i].name+'", '+
                           '"'+jsondata[i].description+'", '+
                           '"'+jsondata[i].make+'", '+
                           '"'+jsondata[i].price+'")'+
                  ' ON DUPLICATE KEY UPDATE '+
                      'desc=\''+jsondata[i].description+'\','+
                      'price=\''+jsondata[i].price+'\';');
    });
您只能使用

对于此特定问题,
INSERT或REPLACE
可能是您想要的:

tx.executeSql('INSERT OR REPLACE INTO Pricelist2(id,name,desc,make,price)'+
              'VALUES (?,?,?,?,?)',
              [jsondata[i].id,
               data[i].name,
               jsondata[i].description,
               jsondata[i].make,
               jsondata[i].price]);
(如果记录已经存在,
名称
制作
也将被替换。)

您只能使用

对于此特定问题,
INSERT或REPLACE
可能是您想要的:

tx.executeSql('INSERT OR REPLACE INTO Pricelist2(id,name,desc,make,price)'+
              'VALUES (?,?,?,?,?)',
              [jsondata[i].id,
               data[i].name,
               jsondata[i].description,
               jsondata[i].make,
               jsondata[i].price]);
(如果记录已存在,
name
make
也将被替换。)