I am working in cordova. I created one database and table in it. It's work perfectly. But When I run application again database is not exist. It was deleted. I am using sqlite plugin http://ift.tt/1O3yCJy
Please help me. I wasted my lots of time for that didn't get any solution.
My code for create database
define([
'cordova',
'logs'
], function () {
SQLiteDB = function () {
var self = this;
this.dbName = 'AppDb.s3db';
this.db = null;
/*
Populate database
*/
this.openDatabase = function (callback) {
this.db = sqlitePlugin.openDatabase({
name: this.dbName, location: 2, createFromLocation: 1
});
this.db.transaction(
function (tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS myDB(pax_id integer primary key, user_token text)');
if (typeof callback == 'function') {
callback.call();
}
},
this.dbErrorHandler
);
},
this.addLoginDetail = function (pax_id, user_token, successCallback) {
var that = this;
if (!this.db)
this.openDatabase();
that.db.transaction(
function (tx) {
tx.executeSql("INSERT INTO myDB (pax_id, user_token) VALUES (?,?)", [pax_id, user_token], function (tx, res) {
console.log("Save device config to local database");
Logs.logWrite("Save device config to local database");
if (typeof successCallback == 'function') {
var config_settings = null;
config_settings = JSON.parse(val.CONFIG_SETTINGS);
config_settings.LAST_UPDATE_TIME = lastUpdateTime;
if (!config_settings.APP_TYPE)
config_settings.APP_TYPE = 'D';
successCallback.call(config_settings);
}
});
},
that.dbErrorHandler
)
}
this.getLoginDetail = function (successCallback) {
var that = this;
console.log('call Login detail in local database');
Logs.logWrite('call getEmployee in local database');
if (!this.db)
this.openDatabase();
this.db.transaction(
function (tx) {
tx.executeSql("SELECT pax_id, user_token from myDB;", [],
function (tx, res) {
if (typeof successCallback == 'function') {
var employee = null;
var config_settings = null;
if (res.rows.length > 0) {
config_settings = JSON.parse(res.rows.item(0).config_settings);
console.log("dbLogin =============>> " + JSON.stringify(config_settings));
employee = res.rows.item(0);
}
successCallback.call(config_settings);
}
},
that.dbErrorHandler
)
},
that.dbErrorHandler
);
}
}
return SQLiteDB;
});
Aucun commentaire:
Enregistrer un commentaire