我的iOS项目上有一个SQLITE数据库,可以从本机IOS代码访问该数据库。我可以访问它并从中读取数据。
您可以在下面的图片中看到我的操作方式和项目结构:
我尝试使用Phonegap做同样的事情:
var db;
var shortName = 'myTestDb.db';
var version = '1.0';
var displayName = 'myTestDb';
var maxSize = 65535;
// list the values in the database to the screen using jquery to
//update the #lbUsers element
function ListDBValues() {
if (!window.openDatabase) {
alert('Databases are not supported in this browser.');
return;
}
$('#myDbElements').html('');
db.transaction(function(transaction) {
transaction.executeSql("SELECT FIRST_NAME FROM dbo_RE_USER;", [],
function(transaction, result) {
console.log("result");
if (result != null && result.rows != null) {
console.log("result is not null");
for (var i = 0; i < result.rows.length; i++) {
var row = result.rows.item(i);
//console.log(row);
debugObject(row);
$('#myDbElements').append('<br>' + row["FIRST_NAME"]);// + " " + row.LAST_NAME );
}
}
PrecApp.I_SCROLL.refresh();
},errorHandler);
},errorHandler,nullHandler);
return;
}
function debugObject(obj) {
console.log("ROW:");
for (n in obj)
// alert(n + ":" + obj[n]);
console.log(n + ":" + obj[n]);
}
但是找不到我的dbo_re_users表。为什么?
最佳答案
使用JavaScript打开的数据库是一个完全不同的数据库-它具有相同的名称,但不在应用程序捆绑包中,后者是只读的。
如果需要访问特定的数据库文件,则需要使用插件。
关于ios - 无法使用phonegap打开sqlite数据库,但在 objective-c 上工作正常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13493306/