我想在混合移动应用程序中使用Sqlite插件(Cordova)创建一个示例项目

I want to create a sample project using Sqlite plugin (Cordova) in Hybrid Mobile Apllication?

本文关键字:Cordova 创建 一个 项目 插件 移动 混合 应用程序 Sqlite      更新时间:2023-09-26

我引用了 https://github.com/litehelpers/Cordova-sqlite-storage 中提到的代码。不生成数据库文件。任何帮助都应不胜感激。

document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
  var db = window.sqlitePlugin.openDatabase({name: 'my.db', location: 'default'});
  db.transaction(function(tx) {
    tx.executeSql('DROP TABLE IF EXISTS test_table');
    tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)');
    // demonstrate PRAGMA:
    db.executeSql("pragma table_info (test_table);", [], function(res) {
      console.log("PRAGMA res: " + JSON.stringify(res));
    });
    tx.executeSql("INSERT INTO test_table (data, data_num) VALUES (?,?)", ["test", 100], function(tx, res) {
      console.log("insertId: " + res.insertId + " -- probably 1");
      console.log("rowsAffected: " + res.rowsAffected + " -- should be 1");
      db.transaction(function(tx) {
        tx.executeSql("select count(id) as cnt from test_table;", [], function(tx, res) {
          console.log("res.rows.length: " + res.rows.length + " -- should be 1");
          console.log("res.rows.item(0).cnt: " + res.rows.item(0).cnt + " -- should be 1");
        });
      });
    }, function(e) {
      console.log("ERROR: " + e.message);
    });
  });
}

请默认提供文件位置

var db = window.sqlitePlugin.openDatabase({name: 'my.db', location: 'abc.txt'});