简体   繁体   English

数据库语句在Google Chrome中不起作用

[英]Database statement is not working in google chrome

I am running chrome 43.0 . 我正在运行chrome 43.0 In console i am running below command: 在控制台中,我正在以下命令下运行:

  >>  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

The problem is its not inserting any data in fileLog table. 问题是它没有在fileLog表中插入任何数据。

You have to create the table fileLog before you insert the values into it as follows : 您必须先创建表fileLog,然后将值插入到表中,如下所示:

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

And you can select values from it as 您可以从中选择值

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);
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM