简体   繁体   中英

Database statement is not working in google chrome

I am running 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.

You have to create the table fileLog before you insert the values into it as follows :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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