我是Phonegap的新手。我想从 SD 卡读取数据库文件。我通过 SQLite 浏览器创建了一个“演示”数据库,然后将其放入 SD 卡中。现在我想从 SDcard 中读取它。我正在使用以下代码,但它不起作用。
function save_address(name) {
var db;
db = window.openDatabase("../../../mnt/sdcard/demo", "1.0", "demo", 200000);
console.log("DataBaseObject::::::::::"+db);
db.transaction(populateDB, errorCB, successCB);
}
function populateDB(tx) {
tx.executeSql('INSERT INTO tbl_DEMO (id, name, number)VALUES(1,"Firstrow",1)');
tx.executeSql('INSERT INTO tbl_DEMO (id, name, number) VALUES (2, "Second row",2)');
}
// Query the database
//
function queryDB(tx) {
tx.executeSql('SELECT * FROM tbl_DEMO', [], querySuccess, errorCB);
}
// Query the success callback
//
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);
}
}
// Transaction error callback
//
function errorCB(err) {
console.log("Error processing SQL: "+err.code);
}
// Transaction success callback
//
function successCB() {
var db = window.openDatabase("../../../mnt/sdcard/demo", "1.0", "Cordova Demo", 200000);
db.transaction(queryDB, errorCB);
}