Chrome的SQLITE中的批量插入语句

时间:2014-02-07 14:13:22

标签: database html5 sqlite google-chrome

我无法在chrome内置数据库中批量插入。 我尝试了以下方法

db.transaction(function(query){
  query.executeSql("BEGIN IMMEDIATE TRANSACTION",[],nullDataHandler, errorHandler)

   query.executeSql('INSERT INTO  cstmr_info (lst_nam  ,fst_nam ,doc,email ,mob_no ,hosp )VALUES("a","b","c","d",6256,"dcd")',[],nullDataHandler, errorHandler);
   query.executeSql('INSERT INTO  cstmr_info (lst_nam  ,fst_nam ,doc,email ,mob_no ,hosp )VALUES("a","b","c","d",6256,"dcd")',[],nullDataHandler, errorHandler);


  query.executeSql("COMMIT TRANSACTION",[],nullDataHandler, errorHandler);

        });

我尝试了这个但是它会抛出错误

db.transaction(function(query){

       query.executeSql('INSERT INTO  cstmr_info (lst_nam  ,fst_nam ,doc,email ,mob_no ,hosp )VALUES("a","b","c","d",6256,"dcd"),("a","b","c","d",6256,"dcd")',[],nullDataHandler, errorHandler);

            });

但这也不受支持

1 个答案:

答案 0 :(得分:0)

transaction功能已经完成了交易。

自SQLite 3.7.11以来,支持单个VALUES子句中的多个记录,因此您无法依赖此记录。

在单个事务中使用多个INSERT:

db.transaction(function(tx){
    tx.executeSql('INSERT INTO cstmr_info(...) VALUES(...)', ...);
    tx.executeSql('INSERT INTO cstmr_info(...) VALUES(...)', ...);
});