简体   繁体   English

无法访问Cordova的SQL-lite存储插件

[英]Cannot access cordova's SQL-lite storage plugin

I am building a simple app using Cordova and AnglerJS, for the database works I decided to use the cordova-sqlite-storage . 我正在使用Cordova和AnglerJS构建一个简单的应用程序,对于数据库工作,我决定使用cordova-sqlite-storage Using Cordova's CLI command cordova plugin add https://github.com/litehelpers/Cordova-sqlite-storage.git I was able to install the plugin. 使用Cordova的CLI命令cordova plugin add https://github.com/litehelpers/Cordova-sqlite-storage.git我能够安装该插件。 But when I try to use it I get this error: 但是当我尝试使用它时,出现此错误:

Uncaught TypeError: Cannot read property 'openDatabase' of undefined application.js:6 未捕获的TypeError:无法读取未定义的application.js的属性'openDatabase':6

Here is the code: 这是代码:

document.addEventListener('deviceready', function(){
    var db = window.sqlitePlugin.openDatabase({name: "database.db", location: 2});
});

I am suspecting that the plugin itself/installation wasn't correct, are there any farther steps than using the cordova plugin add ... ?! 我怀疑插件本身/安装不正确,是否有比使用cordova plugin add ...更远的步骤?!

A Cordova/PhoneGap litehelpers/Cordova-sqlite-storage plugin open and use sqlite databases only on: Cordova / PhoneGap litehelpers / Cordova-sqlite-storage插件仅在以下情况下打开并使用sqlite数据库:

  • Android Android的
  • iOS iOS版
  • Windows Universal(8.1) // Not Windows and Browser Windows Universal(8.1)// 不是Windows和浏览器
  • Amazon Fire-OS 亚马逊Fire-OS
  • WP(7/8) WP(7/8)

with HTML5/Web SQL API. HTML5 / Web SQL API。

This plugin in Chrome or Firefox does not work. Chrome或Firefox中的此插件不起作用。

For example, for Android devices, if you have SQLite file "database.db" in your project folder [ mobileapp\\www\\ ] to connect database file just: 例如,对于Android设备,如果您在项目文件夹[mobileapp \\ www \\]中具有SQLite文件“ database.db”,则仅用于连接数据库文件:

var db = window.sqlitePlugin.openDatabase({name: "database.db", createFromLocation: 1});

Some simple code: 一些简单的代码:

db.transaction(function(tx)
{
    tx.executeSql('select * from TABLENAME;', [], function(tx, res)
    {
        console.log(res.rows);   
    }, 
    function(e){
        console.log("error: "+e.message);
    });
}); 

More informations: litehelpers/Cordova-sqlite-storage Docs 详细信息: litehelpers / Cordova-sqlite-storage文档

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

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