chronotrigga
chronotrigga

Reputation: 609

SQLite - Problems opening a db that exists

I am running the cordova sqlite-ext plugin (https://github.com/litehelpers/cordova-sqlite-ext) with my cordova android project and have attempted to open a pre-existing sqlite .db. I keep seeing the error below, saying that it is opening my database but not finding the tables.

I decided to rename the database completely to "wibblewobble" to see if it would produce an unknown error since wibblewobble does not exist but I am still getting the same result.

Anyone using sqlite plugin can explain why this is appearing in my logcat and my content is not appearing? Why am I receiving fake errors saying the database is opening when it clearly is not?

 03-01 10:59:22.210 850-911/cafr.b.appfinder W/PluginManager: THREAD WARNING: exec() call to SQLitePlugin.open blocked the main thread for 71ms. Plugin should use CordovaInterface.getThreadPool().
 03-01 10:59:22.510 850-850/cafr.b.appfinder I/chromium: [INFO:CONSOLE(106)] "new transaction is waiting for open operation", source: file:///android_asset/www/plugins/cordova-sqlite-ext/www/SQLitePlugin.js (106)
 03-01 10:59:23.780 850-850/cafr.b.appfinder I/chromium: [INFO:CONSOLE(80)] "DB opened: wibblewobble.db", source: file:///android_asset/www/plugins/cordova-sqlite-ext/www/SQLitePlugin.js (80)
 03-01 10:59:24.240 850-911/cafr.b.appfinder W/PluginManager: THREAD WARNING: exec() call to SQLitePlugin.backgroundExecuteSqlBatch blocked the main thread for 64ms. Plugin should use CordovaInterface.getThreadPool().
 03-01 10:59:25.880 850-903/cafr.b.appfinder E/SQLiteLog: (1) no such table: MainDatabase
 03-01 10:59:25.890 850-903/cafr.b.appfinder W/System.err: android.database.sqlite.SQLiteException: no such table: MainDatabase (code 1): , while compiling: SELECT DISTINCT Category FROM `MainDatabase`
 03-01 10:59:25.890 850-903/cafr.b.appfinder W/System.err:     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)

Upvotes: 0

Views: 698

Answers (1)

iSandeep
iSandeep

Reputation: 715

I also had this issue and solved it by Using CordovaPlugin class, It's my suggestion either using the plugin create you own by extending the CordovaPlugin class:

class YourClass extends CordovaPlugin{
     public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
           //Your Code here...
           switch(action){
                 case "yourAction":
                         //Your Logic to work with SQLite....
                 break;
           }
     }
}

on Last but not lst, make entry of YourClass in config.xml under xml in res and give a ajax call to this class by using the YourClass name as action.

way to call the class from your web page.

function doTask(){
var success = function(message) {
                    document.getElementById('testResult').innerHTML = message;
                };
                var error = function(message) {
                    document.getElementById('testResult').innerHTML = message;
                };

YourVariable.createEvent(database_Name,query_string, success, error);
}

create a .js file and put the following code:

var YourVariable = {
    createEvent: function(title, location, notes, startDate, endDate, successCallback, errorCallback) {
        cordova.exec(
            successCallback, // success callback function
            errorCallback, // error callback function
            'YourClass', // mapped to our native Java class called "YourClass"
            'yourAction', // with this action name
            [{                  // and this array of custom arguments to create our entry
                "title": title,
                "description": notes,
                "eventLocation": location,
                "startTimeMillis": startDate,
                "endTimeMillis": endDate
            }]
        );
     }
}

Upvotes: 1

Related Questions