【问题标题】:I want to create a sample project using Sqlite plugin (Cordova) in Hybrid Mobile Apllication?我想在混合移动应用程序中使用 Sqlite 插件 (Cordova) 创建一个示例项目?
【发布时间】:2016-08-16 23:17:36
【问题描述】:

我参考了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);
    });
  });
}

【问题讨论】:

  • cordova.js 文件包含在您的 html 中吗?任何错误跟踪?
  • 您在DDMS 中签入数据库了吗?您的数据库将在您的包名称文件夹中。
  • 我从哪里获得cordova.js 文件,有没有可以下载的来源? @甘地
  • 我已经检查了 DDMS ,没有创建任何数据库@jaydroider
  • @AnjaliPatel 在这里查看我给定的答案stackoverflow.com/questions/36743158/…

标签: javascript android html sqlite cordova


【解决方案1】:

请提供默认的文件位置

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

【讨论】:

  • 据我在cordova s​​qlite存储插件的文档中阅读,位置是指创建db文件的路径。所以我猜想为 location 参数指定文件名是不对的。
猜你喜欢
  • 2018-09-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多