0

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>
Arun Kumar T
  • 620
  • 4
  • 12
  • 26

1 Answers1

1

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.

Connor Pearson
  • 63,902
  • 28
  • 145
  • 142
  • Thanks for your suggestion. I provided the script details which I included in my page. Please refer it. And I added this function in the event of device ready function. – Arun Kumar T May 06 '16 at 05:00
  • You are correct, actually I missed to include the following cordova script – Arun Kumar T May 06 '16 at 05:14
  • can you please let me know how to access the Test.sqlite which is placed under 'data' folder? – Arun Kumar T May 06 '16 at 05:19
  • I'd try placing it in your www folder and follow the instructions here. https://github.com/litehelpers/cordova-sqlite-ext#pre-populated-databases – Connor Pearson May 07 '16 at 21:16