javascript - 使用 phonegap API 从 Android 中的 sqlite 检索数据时出现 INVALID_ACCESS_ERR

标签 javascript cordova sqlite

这是我的 Javascript 代码

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

// Populate the database
//
function populateDB(tx) {
    alert("populateDB");
    tx.executeSql('DROP TABLE IF EXISTS DEMO');
    tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
    tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
    tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
}

// Query the database
//
function queryDB(tx) {
    alert("queryDB");
    tx.executeSql('SELECT * FROM DEMO', [], querySuccess, errorCB);
}

// Query the success callback
//
function querySuccess(tx, results) {
    alert("querySuccess");
    // this will be empty since no rows were inserted.
    console.log("Insert ID = " + results.insertId);
    // this will be 0 since it is a select statement
    console.log("Rows Affected = " + results.rowAffected);
    // the number of rows returned by the select statement
    console.log("Insert ID = " + results.rows.length);
}

// Transaction error callback
//
function errorCB(err) {
    alert("errorCB");
    console.log("Error processing SQL: "+err.code);
}

// Transaction success callback
//
function successCB() {
    alert("successCB");
    var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
    db.transaction(queryDB, errorCB);
}

// PhoneGap is ready
//
function onDeviceReady() {
    alert("onDeviceReady");
    var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
    db.transaction(populateDB, errorCB, successCB);
}

但是我收到这个错误日志

D/DroidGap(1674): DroidGap.loadUrl(file:///android_asset/www/index.html)
D/DroidGap(1674): DroidGap: url=file:///android_asset/www/index.html   baseUrl=file:///android_asset/www/
D/DroidGap(1674): DroidGap.init()
D/SoftKeyboardDetect(1674): Ignore this event
D/SoftKeyboardDetect(1674): Ignore this event
D/dalvikvm(1674): GC_FOR_MALLOC freed 1758 objects / 121720 bytes in 172ms
I/Database(1674): sqlite returned: error code = 14, msg = cannot open file at source   line 25467
D/PhoneGapLog(1674): DroidGap:  onExceededDatabaseQuota estimatedSize: 200000    currentQuota: 0  totalUsedQuota: 0
D/PhoneGapLog(1674): calling quotaUpdater.updateQuota newQuota: 200000
D/PhoneGapLog(1674): INVALID_ACCESS_ERR: DOM Exception 15: A parameter or an operation  was not supported by the underlying object.
D/PhoneGapLog(1674): file:///android_asset/www/index.html: Line 232 :  INVALID_ACCESS_ERR: DOM Exception 15: A parameter or an operation was not supported by the    underlying object.
E/Web Console(1674): INVALID_ACCESS_ERR: DOM Exception 15: A parameter or an operation was not supported by the underlying object. at file:///android_asset/www/index.html:232
D/PhoneGapLog(1674): Error processing SQL: 0
D/PhoneGapLog(1674): file:///android_asset/www/index.html: Line 243 : Error processing SQL: 0

我使用的是 Phonegap 1.4.0 版。 这里有什么问题?

最佳答案

不知道您是否已经解决了这个问题,但我使用的是您的相同示例代码,但遇到了同样的问题。该示例不正确。 Phonegap 现在有一个更新的示例。将您的查询方法替换为

function querySuccess(tx, results) {
    var len = results.rows.length;
    console.log("DEMO table: " + len + " rows found.");
    for (var i=0; i<len; i++){
        console.log("Row = " + i + " ID = " + results.rows.item(i).id + " Data =  " + results.rows.item(i).data);
    }
}

关于javascript - 使用 phonegap API 从 Android 中的 sqlite 检索数据时出现 INVALID_ACCESS_ERR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9124707/

相关文章:

javascript - 设备收到 GCM Android 通知但未显示

mysql - SQL:一张表,不同的列名?

javascript - 如何使用 rollup 在 bundle 中包含 import 和 require 语句

javascript - 如何通过点击广告在新窗口中打开链接?

android/phonegap 未捕获类型错误 : Cannot read property 'downloader' of undefined at file

javascript - 为什么在 Win8 Phone Apps 上使用 PhoneGap

python - 在 Sqlite3 中存储字典的字典

.net - 如何根据客户端架构动态加载x86/x64版本的SQLite3.DLL?

javascript - 如何访问 jQuery .on() 的 "first"选择器?

javascript - 如何通过发送请求从 Zoom 获取访问 token ?