Avadhani Y
Avadhani Y

Reputation: 7636

Sqlite Database records are not retrieving when force stopping the Android application

I am developing Android Application using Phonegap 1.4.1.js and jquery.mobile-1.0.1.min.js . I am using openDatabase() for creating the Sqlite Database. The Database is working fine. Here the problem is while the Application is running in the background, the database is working fine. If i FORCESTOP the application manually, the querying the database records is not possible. But the database is existed in the Local Storage of Device. Even the Logcat is not showing any warning or error after reopening the Application.

Here is my Code for implementing the login Details of the user:

     function onDeviceReady() 
     {
          CheckLoginData();
     }
     function checkLoginData() {
    var  db = openDatabase("LoginData", "1.0", "LoginData", 200000);    
        db.transaction(queryLoginData, errorLoginData);

}
function queryLoginData(tx) {
    tx.executeSql("SELECT * FROM LoginData where LoginDate='" + InsertCurrentDate + "'", [], querySuccessLoginData, errorLoginData);
}

function querySuccessLoginData(tx, results) {
    // the number of rows returned by the select statement
      console.log("Insert ID = " + results.rows.length); 
      var len = results.rows.length;
      if((len > 0)) {
          var DBdate = results.rows.item(0).LoginDate;
          var date= new Date();
          var month = date.getMonth()+1;
          var day = date.getDate();
          var year = date.getFullYear();
          var systemDate = year+'-'+month+'-'+day;
          //alert(DBdate +  '    '+systemDate);
          if(DBdate==systemDate)
              {
                    //alert(DBdate +  '    '+systemDate);
                    document.location.href = "#recent";
              }
          else
              {
                    alert("Please Login for Today");
                    document.location.href = "#login";
                    $('#useridBox').val('');
                    $('#passwdBox').val('');
              }
        }
        if(len==0){
            var strURL = document.location.href;
            document.location.href = strURL+"#login";
        }
}

function errorLoginData(err) {
     var strURL = document.location.href;
    document.location.href = strURL+"#login"; 
    //alert("Error while Retrieving Data");
}

Is there any problem in the code. Please help me how to get the database records whenever force stopping the Application.

Upvotes: 1

Views: 486

Answers (1)

coderslay
coderslay

Reputation: 14370

I would prefer you using the latest version of phonegap which is Cordova-1.5.0. There might be some issue in Phonegap(which uses the default database provided by the webview) while force stopping the application.

I have modified the Cordova(https://github.com/Coder-Nasir/incubator-cordova-android) in such a way that it will create the database in Android's Default location which is /data/data/package-name/databases/

By just this simple command

window.openDatabase("something", "1.0", "PhoneGap Demo", 0);

You will get your desired something.db in the above mentioned location..

Upvotes: 1

Related Questions