【问题标题】:Database statement is not working in google chrome数据库语句在谷歌浏览器中不起作用
【发布时间】:2015-06-29 11:41:06
【问题描述】:

我正在运行 chrome 43.0。在控制台中,我运行以下命令:

  >>  var db1 = openDatabase('testDB', '', 'my first database', 2 * 1024 * 1024, function(d){console.log(d);});

  >>  undefined

  >>  db1.transaction(function (tx) { 
      console.log("....................."); 
      console.log(tx.executeSql("INSERT INTO fileLog (fileName, bucketName) VALUES ('123','synergies')"));
    });

  >>  undefined
     .....................
      undefined

问题是它没有在fileLog 表中插入任何数据。

【问题讨论】:

  • 问题是没有错误回调。

标签: javascript sqlite google-chrome opendatabase


【解决方案1】:

您必须先创建表 fileLog,然后再将值插入其中:

db1.transaction(function (tx) { 
tx.executeSql('CREATE TABLE IF NOT EXISTS fileLog (fileName,bucketName )');    });

你可以从中选择值

db1.transaction(function (tx) { 
      tx.executeSql('SELECT * FROM fileLog ', [], function (tx, results) {
     for (var i = 0; i < results.rows.length; i++){
         console.log(results.rows.item(i).fileName," ",results.rows.item(i).bucketName);
      }

   }, null);
    });

【讨论】:

    猜你喜欢
    • 2011-02-15
    • 2020-04-11
    • 1970-01-01
    • 1970-01-01
    • 2012-10-12
    • 2016-01-25
    • 2013-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多