storesafe / cordova-sqlite-storage

A Cordova/PhoneGap plugin to open and use sqlite databases on Android, iOS and Windows with HTML5/Web SQL API
Other
2.15k stars 715 forks source link

Existing database not loading #439

Closed lulu2727 closed 8 years ago

lulu2727 commented 8 years ago

I have created a basic database using SqlliteBrowser. I have placed my database in my www directory of an ionic app. The ionic app doesn't do anything, i'm just trying to reference the created database. This code below is my app :

`angular.module('app', ['ionic', 'ngCordova'])

.run(function ($ionicPlatform, $cordovaSQLite, $rootScope) {
    $ionicPlatform.ready(function () {
        // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
        // for form inputs)
        if (window.cordova && window.cordova.plugins.Keyboard) {
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
            cordova.plugins.Keyboard.disableScroll(true);

        }
        if (window.StatusBar) {
            // org.apache.cordova.statusbar required
            StatusBar.styleDefault();
        }

        $rootScope.db = window.sqlitePlugin.openDatabase({ name: "base.db", location: 2, createFromLocation: 1 });
        $rootScope.db.executeSql("SELECT name FROM sqlite_master WHERE type='table'", [], function (res) {
            console.log(res.rows.item(0));
            console.log(res.rows.item(1));                                                                                                                                               
        });
    })
})`

I'm testing it on an nexus 6 using 'cordova run android'. I have access to google chrome console thanks to remote debugging (chrome://inspect). I have added Cordova-sqlite-storage plugin to cordova. However, window.sqlitePlugin.openDatabase create another database and doesn't use the existing one. Where do i need to put the existing database for the plugin to find it.

brodycj commented 8 years ago

This project does not support the pre-populated database (createFromLocation) feature, it is now supported by cordova-sqlite-ext. I will update README with a clear note when I get a chance.

Also @jdnichollsc contributed a sample Ionic project with a pre-populated database at: https://github.com/jdnichollsc/Ionic-Starter-Template

coommark commented 8 years ago

@brodybits You are doing such an awesome job, thanks a million! So I want to ask, did you say

This project does not support the pre-populated database (createFromLocation) feature

Because for the past few weeks I have been using it (createFromLocation) and it has been working fine. I have been using two dbs in my project together with the cordova-plugin-dbcopy, however yesterday I created another db and no matter what I do, I get "message": "No such table" code 1 error. Problem is:

  1. I have not updated anything on the project.
  2. I created the db exactly the same way as I created the rest. I even created and tested about 10 other dbs, same error.

What could be the possible issue here?

brodycj commented 8 years ago

@coommark I think you asked the same question in litehelpers/cordova-sqlite-ext#14. Closing this one.