简体   繁体   English

为什么我不能使用cordova-sqlite-storage?

[英]Why I cannot use cordova-sqlite-storage?

I am writing an android app, I am using phonegap and with weinre for debugging. 我正在编写一个Android应用程序,正在使用phonegap并使用weinre进行调试。

Some info: 一些信息:

$ phonegap -v
5.3.9
$ cordova plugin list
cordova-plugin-whitelist 1.2.0 "Whitelist"
cordova-sqlite-storage 0.7.14 "Cordova sqlite storage plugin"

The plugin is installed, but when I run it with phonegap and open it in my phone, nothing shows up in the console. 该插件已安装,但是当我使用phonegap运行它并在手机中打开它时,控制台中没有任何显示。 No error, nothing. 没错,没事。 The window object was printed in the console, but not everything else. 窗口对象已打印在控制台中,但没有打印其他所有内容。

I am using the default configuration of phonegap, can anybody tell me why this is happenning? 我使用的是phonegap的默认配置,有人可以告诉我为什么会这样吗?

This is the code I have written in my js script. 这是我在js脚本中编写的代码。

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady(event) {                              

    console.log(window);                                     
    //var db = window.sqlitePlugin.openDatabase({name: "my.db"});
    //var openDatabase = sqlitePlugin.openDatabase;          
    console.log(window.sqlitePlugin);                        
    console.log(window.sqlitePlugin.openDatabase);           

    var db = window.sqlitePlugin.openDatabase({name: "test.db"},
        function(db) {                                       
            console.log('db open succeeded');                
        },                                                   
        function(err) {                                      
            console.log('Open database ERROR: ' + JSON.stringify(err));
        }                                                    
    );                                                       

    db.executeSql("create table tmp 'column1' INT;", [], function (res) {
        console.log('got stringlength: ' + res.rows.item(0).stringlength);
    }, function(error) {                                     
        console.log('SELECT error: ' + error.message);       
    });                                                      

    db.executeSql("SELECT LENGTH('tenletters') AS stringlength", [], function (res) {
        console.log('got stringlength: ' + res.rows.item(0).stringlength);
    }, function(error) {                                     
        console.log('SELECT error: ' + error.message);       
    });                                                      
}                                                            

I would suggest not using weinre, unless you really have to. 我建议不要使用weinre,除非您确实需要。 Built-in alternatives for some devices, listed here: http://people.apache.org/~pmuellr/weinre/docs/latest/ 某些设备的内置替代品,在此处列出: http : //people.apache.org/~pmuellr/weinre/docs/latest/

Hi Kindly do something like this in your onDeviceReady(). 嗨,请在您的onDeviceReady()中执行类似的操作。 Maybe it is unable to work with sqllite db . 也许它无法与sqllite db一起使用。

onDeviceReady: function() {
        app.receivedEvent('deviceready');
          if(window.sqlitePlugin !== undefined) {
            console.log('opening sqlite DB ');
            db = window.sqlitePlugin.openDatabase("ECM_MOBILE");
        } else {
            console.log('opening Web SQL DB ');
            db = window.openDatabase("ECM_MOBILE", "1.0", "Cordova Demo", 200000);
        }   

    }

if sqlite is not being installed properly then , you need to fix the installation for sqlite db . 如果sqlite安装不正确,则需要修复sqlite db的安装。

在打开数据库时,必须在新版本的SQLite插件位置中进行设置:

var db = window.sqlitePlugin.openDatabase({name: "my.db", location: "default"}); 

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

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