2016-12-16 7 views
0

ユーザーが突然私のアプリケーションから別のユーザーに切り替えるか、電話を再起動したときに、以前のログインから既に設定されたデータを読み込む際に問題が発生しました。ログインに成功した後に設定したデータは、SQLiteデータベースに保存されます。サンプルソースコードにAndroidでのログイン中にSQLiteからデータを読み込む

.controller('LoginCtrl', function($scope, $ionicPopup, $state,$http,ServerEndPoint,localStorageService,$cordovaGeolocation,$ionicActionSheet,dataShare,$ionicPush,loading,$rootScope,$cordovaSQLite) { 
 
     
 
     $scope.data = {}; 
 
     
 
      //Does not work 
 
      $scope.init = function() 
 
      { 
 
       $scope.load(); 
 
      }; 
 

 
      if(localStorageService.get("tradie_id") !== null && localStorageService.get("phone_no") !== null) { 
 
      $state.go('menu.map'); 
 
      } 
 
      
 
      //This is called from login form submit button click 
 
      $scope.authenticateUser = function(loginForm){ 
 
       //Authenticating user from the server, after successful login 
 
       //This one works 
 
       $scope.addInfo(res.data.user_id,res.data.first_name,res.data.phone_no,status); 
 
       
 
       $state.go('menu.map'); 
 
      } 
 
    
 
    $scope.addInfo = function(user_id,first_name,phone_no,status){ 
 
    var query = "INSERT INTO user_data(user_id,first_name,phone_no,status) VALUES(?,?,?,?)"; 
 
    $cordovaSQLite.execute(db,query,[user_id,first_name,phone_no,status]); 
 
    $scope.load(); 
 
    } 
 
    
 
    $scope.load = function(){ 
 
    
 
    $scope.alldata = []; 
 
    $cordovaSQLite.execute(db,"SELECT * FROM user_data").then(function(result){ 
 
     if(result.rows.length) 
 
     { 
 
      for(var i=0;i<result.rows.length;i++) 
 
      { 
 
      $scope.alldata.push(result.rows.item(i)); 
 
      } 
 
       
 
       localStorageService.set("user_id", $scope.alldata[0].tradie_id); 
 
       localStorageService.set("first_name", $scope.alldata[0].first_name); 
 
       localStorageService.set("phone_no", $scope.alldata[0].phone_no); 
 

 
     }else 
 
     { 
 
      console.log("No data found"); 
 
     } 
 
    },function(error){ 
 
     console.log("error "+err); 
 
    }) 
 
    } 
 
      
 
})

任意の提案やポインタは高く評価されます。私は最初のアプリの準備ができたときに、DBを作成したり、開いていなかったと思うのイオンバージョン1.

答えて

0

を使用しています:

var db = $cordovaSQLite.openDB({ name: "my.db" }); 
関連する問題