【发布时间】:2015-03-24 20:00:56
【问题描述】:
我想在我的 .js 文件所在的文件夹中打开一个名为 qw.db 的数据库 但是,似乎它创建了一个新文件 qw 而不是打开我自己的 db 文件 这是我的代码
function onDeviceReady() {
var shortName = 'qw';
var version = '1.0';
var displayName = 'qwq';
var maxSize = 65535;
if (!window.openDatabase) {
alert('!! Databases are not supported in this Device !! \n\n We are sorry for the inconvenience and are currently working on a version that will work on your phone');
}
db = openDatabase(shortName, version, displayName, maxSize);
createAllTables(db);
}
function createAllTables(db){
db.transaction(function (transaction) {
transaction.executeSql("CREATE TABLE IF NOT EXISTS model(ModelId INTEGER PRIMARY KEY AUTOINCREMENT,ModelNumber varchr(50))");
});
db.transaction(function(transaction){
var rowCount = 'SELECT * FROM model';
transaction.executeSql(rowCount,[],function(transaction,result){
if(result.rows.length == 0){
var sqlString = 'INSERT INTO model (ModelId,ModelNumber) VALUES("200","Female")';
transaction.executeSql(sqlString);
}
});
});
}
如果需要,这里是一个参考Phonegap Offline Database
【问题讨论】:
-
@Ved 似乎是专门为 android 设计的。我希望我的应用适用于 android、ios 和 windows 设备。
-
好的 .. 看我的另一篇文章:stackoverflow.com/questions/26629244/…
标签: javascript database cordova phonegap-plugins