Search code examples
androidangularjsionic-frameworkcordova-pluginsngcordova

Ionic and AngularJS are used. Downloaded DB from server, tables are not detected in SQLite DB for Android but working in iOS


Background of the application:

  1. Downloading DB using $cordovaFileTransfer.
  2. Unzipping it using $cordovaZip
  3. Accessing DB using window.sqlitePlugin.openDatabase({name: 'name of the DB'})

Saving the DB at location, 'cordova.file.dataDirectory;'

When I try executing commands on DB using the below code:

    db.executeSql(query, parameters, function (result) {
    //alert('execution result is in console');
    console.log('Check SELECT result from rows: ' +
    JSON.stringify(result.rows.item(0)));
    //alert('Check SELECT result from rows: ' +
    JSON.stringify(result.rows.item(0)));
    console.log('Check SELECT result from rows_only result: ' +
    JSON.stringify(result));
    q.resolve(result);
    },function(error){
    alert('Error from factory DBA self.query: ' + JSON.stringify(error));
    q.reject(error);
    });

For iOS everything is working fine and I see result in the success function whereas in Android, Its entering error block saying "sqlite prepare statement error - no such table"

Note: I was getting "EROF error" previously on Android before changing db location from documentsDirectory to dataDirectory.


Solution

  • Instead of dataDirectory, /data/data/{appidentifier}/databases/ should be used!!!