0
我使用Ionic/Cordova SQLite插件,我希望能夠在調用特定函數之前檢查數據庫是否存在。如果我使用openDatabase("db", "", "name", dbSize, function() { };
,只有在沒有數據庫時纔會調用它,但是如果我關閉Android應用並重新啓動,openDatabase()
內的代碼根本不會被調用。如果db已經創建,應該調用它嗎?有沒有另一種方法來檢查數據庫已經創建?檢查SQLite數據庫已創建
基本上,我需要調用一個函數後,我檢查有一個數據庫。
db = openDatabase("dbn", "", "manager", dbSize, function() {
console.log('is called'); // only shows when first creating db
// USER table create
db.transaction(function (tx) {
//tx.executeSql('DROP TABLE grips.db.user');
tx.executeSql('CREATE TABLE IF NOT EXISTS user (id integer primary key,active_user, firstname, lastname, email, age, gym_id integer, set_time integer, date_created integer)');
tx.executeSql('CREATE TABLE IF NOT EXISTS sets (id integer primary key,machine_name, device_id integer, weight_val integer, user integer,reps, exercise_id integer, workout_id, gym_id integer, calories,time_ago text, date_created integer)');
tx.executeSql('CREATE TABLE IF NOT EXISTS devices (id integer primary key,mac_id text, device_type,gym_id integer,machine_id integer,machine_name,date_created integer)');
tx.executeSql('CREATE TABLE IF NOT EXISTS workouts (id integer primary key,user integer,date_created integer)');
tx.executeSql('CREATE TABLE IF NOT EXISTS pt_workouts (id integer primary key, img_url, name, video_url, admin_user integer, gym_id integer, gif_url, search_img, instructions, trainer_name, user_img, date_created integer)');
}, function (error) {
}, function() {
});
}, function (error) {
console.log('open db second error');
},function() {
console.log('open db second');
});