我正在使用jquery mobile,SQlite数据库,Cordova
当我的应用程序关闭时请帮助我,然后当我打开我的应用程序时,即使我的数据库已创建,然后它也将转到我的first.js文件的其他部分并再次创建数据库
我的JQuery脚本: -
我正在使用两个脚本
first.js
if(db){
// Database is going to update.
alert("Database exist");
userAuthentication();
}else{
DB_Create();
alert("database created");
userAuthentication();
}
second.js
//全局变量
var db;
var short_Name = 'E_DB';
var version = '1.0';
var display_Name = 'E_DB';
var max_Size = '65535';
var flags = true;
userAuthentication(){
if(flags){
flags=false;
alert("hello");
}else{
alert("hi");
}
}
DB_Create(){
db = window.openDatabase(short_Name, version, display_Name, max_Size);
db.transaction(function(transaction) {
transaction.executeSql('DROP TABLE IF EXISTS Out');
transaction.executeSql('CREATE TABLE IF NOT EXISTS Out(id INTEGER PRIMARY KEY AUTOINCREMENT)');
});
}
答案 0 :(得分:3)
在deviceReady中创建DB2并随时调用userAuthentication可以解决您的问题。