Hi all,
I’m using SQLite to store credentials data before using SQLite i used to session storage (it’s not persist).
I got success when create table and insert some data, but when i try to select data by init my app return blank, there is nothing error or log cause i used Xcode to run this (iOS)
here my code
'use strict';
var db = null;
angular.module('app', ['ionic', 'ngCordova'])
.run(function($ionicPlatform, $cordovaSQLite, DSCacheFactory) {
$ionicPlatform.ready(function() {
//SQLite database
db = $cordovaSQLite.openDB({ name: "my.db" });
//create tables
db.transaction(function(tx) {
//create session table
tx.executeSql('CREATE TABLE IF NOT EXISTS session (id integer primary key, name varchar(50), value text)');
}, function(e) {
console.log("ERROR: " + e.message);
});
});
})
here my auth service
//auth.js
'use strict';
angular.module('logiseraApp').service('auth', function($http, $q, $cordovaSQLite, $window, Constants){
var userdata = {};
var logged_in = false;
this.init = function() {
//check from table session
var query = "SELECT value from session where name = ?";
$cordovaSQLite.execute(db, query, ["userdata"]).then(function(res) {
if(res.rows.length > 0){
userdata = JSON.parse(res.rows.item(0).value);
}
}, function (err) {
console.error(err);
});
}
this.setUserdata = function(data) {
var userdataJSON = JSON.stringify(data);
//$window.sessionStorage["userdata"] = userdataJSON;
//insert session data into session table
var query = "INSERT INTO session (name, value) VALUES (?,?)";
$cordovaSQLite.execute(db, query, ["userdata", userdataJSON]).then(function(res) {
console.log("data was stored: " + res.insertId);
}, function (err) {
console.error(err);
});
userdata = data;
}
this.init();
})
Thank you all,