簡體   English   中英

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

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

我正在編寫一個Android應用程序,正在使用phonegap並使用weinre進行調試。

一些信息:

$ 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"

該插件已安裝,但是當我使用phonegap運行它並在手機中打開它時,控制台中沒有任何顯示。 沒錯,沒事。 窗口對象已打印在控制台中,但沒有打印其他所有內容。

我使用的是phonegap的默認配置,有人可以告訴我為什么會這樣嗎?

這是我在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);       
    });                                                      
}                                                            

我建議不要使用weinre,除非您確實需要。 某些設備的內置替代品,在此處列出: http : //people.apache.org/~pmuellr/weinre/docs/latest/

嗨,請在您的onDeviceReady()中執行類似的操作。 也許它無法與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);
        }   

    }

如果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