我正在尝试将离子1.7.16与Cordova SQLitePlugin(https://github.com/litehelpers/Cordova-sqlite-storage)用于Android。根据(https://github.com/litehelpers/Ionic-sqlite-database-example)的例子,我写的代码如下:
document.addEventListener('deviceready', function () {
db = window.sqlitePlugin.openDatabase({ name: 'test.db', location: 'default' }, function () {
alert("DB opened");
db.transaction(function (tr) {
tr.executeSql("SELECT upper('Test string') AS upperString", [], function (tr, rs) {
console.log('Got upperString result: ' + rs.rows.item(0).upperString);
});
});//end transaction
alert("after Transaction");
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS people (id integer primary key, firstname text, lastname text)");
}, function (err) {
console.log('Open database ERROR: ' + JSON.stringify(err));
}
);//end openDatabase
}); //end addEventListener
我能够看到所有警报,但没有来自console.log的输出。打开数据库时我没有看到任何错误,但我在logcat中看到,执行事务时出错。错误是:
unexpected error
org.json.JSONException: No value for qid
at org.json.JSONObject.get(JSONObject.java:389)
at org.json.JSONObject.getString(JSONObject.java:550)
at org.pgsqlite.SQLitePlugin.executeAndPossiblyThrow(SQLitePlugin.java:145)
at org.pgsqlite.SQLitePlugin.execute(SQLitePlugin.java:82)
at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:97)
at org.apache.cordova.PluginManager.exec(PluginManager.java:132)
at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59)
at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41)
at com.android.org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
at com.android.org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:53)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61)
getSlotFromBufferLocked: unknown buffer: 0xf3e17160
我无法在线找到任何帮助。我在Android设备(One Plus One,sdk 23)和genymotion虚拟设备(google nexus api 23)上测试了我的代码。