Search code examples
angularjssqlitecordovahybrid-mobile-apptelerik-appbuilder

Access the SQLite db which is externally created


I am creating a hybrid app by telerik app builder in visual studio. I am not able to access sqlite db which is created externally. But I can access the db which is created at run time. I referred some sites, those solutions are not worked for me. The following code will create db and access it while run time

var app = {};
app.db = null;

app.openDb = function () {
    var dbName = "Test.sqlite";

    //DB creation for Simulator
    if (window.navigator.simulator === true) {
        app.db = window.openDatabase(dbName, "1.0", "Test Database", 1073741824);
        console.log("Database Created!");
    }
    //DB creation for devices
    else {
        app.db = window.sqlitePlugin.openDatabase(dbName);
        console.log("Database Accessed!");
    }
}

I want to access the database which is present in the data folder. Please refer the image.

enter image description here

I tried to place the db in www folder and try to access it by the following code

app.db = window.sqlitePlugin.openDatabase({name: "Test.db", createFromLocation: 1});

It will give the following error

Uncaught TypeError: Cannot read property 'openDatabase' of undefined

So, how can I access the externally created sqlite db?

I included the following scripts in the project

 <script src="js/jquery-2.1.0.min.js"></script>
 <script src="js/angular.min.js"></script>
 <script src="js/ng-cordova.min.js"></script>

Solution

  • It looks like your issue is that window.sqlitePlugin is undefined. Are you sure the plugin is properly installed? Also, you must wait until the deviceReady event before using window.sqlitePlugin.