brodycj / cordova-sqlite-ext

A Cordova/PhoneGap plugin to open and use sqlite databases on Android/iOS/macOS/Windows with REGEXP (Android/macOS/iOS) and pre-populated databases (Android/iOS/macOS/Windows)
Other
72 stars 55 forks source link

Failed to load populated database #63

Open CampaUTN opened 7 years ago

CampaUTN commented 7 years ago

Hi I cant load a populated database, its notrecognizing the .db file so its creating a new empty one. I have the plugins, the code is copied from here (also tried a lot of different sources): https://github.com/iursevla/ionic2-PreDB

The plugin is acctually working? Because I see travis failing In case the last version is working, do am i missing something apart from the 'guide' of that repository i have copied?

Thank you very much

private options = { name: "datos.db", location: 'default', createFromLocation: 1 }; private queryNames = "SELECT * FROM testTable"; public names: String[] = [];

constructor(public navCtrl: NavController, private sqlite: SQLite, private platform : Platform) {
this.platform.ready().then(() => {
    this.sqlite.create(this.options).then((db: SQLiteObject) => {
      db.executeSql(this.queryNames, {}).then((data) => {
        let rows = data.rows;
        alert(JSON.stringify(rows));
      }, err => {
          alert(JSON.stringify(err));
      })
    });
    })
  }

==> Return: no such testTable and sqlite_master no rows

sofarojo commented 7 years ago

Happens to me too

shkhalid commented 7 years ago

Did you found any solutions? i am also facing this problem.

sofarojo commented 7 years ago

Nope. It's seems that is not supported yet. The only way I found so far is prepopulate the database when loading for first time.

On Aug 24, 2017 23:01, "Shah Khalid" notifications@github.com wrote:

Did you found any solutions? i am also facing this problem.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/litehelpers/cordova-sqlite-ext/issues/63#issuecomment-324756671, or mute the thread https://github.com/notifications/unsubscribe-auth/AD5F2HMAKYeE3oXVZyGmu6ZRJ31qjAFhks5sbeS9gaJpZM4Ot0NV .

ergurjeet commented 7 years ago

For me it's working flawlessly in Android, however, it's creating an empty DB in IOS 11. Any solution or workaround will be appreciated.

sofarojo commented 7 years ago

@ergurjeet How did you make it work in Android?? I still got empty DB instead of my prepopulated one

uselessai commented 7 years ago

I am fancing the same error in iOS.. the same code in android is working perfectly..

sofarojo commented 7 years ago

@DetoloX which code is working for you? i can't make it work in android

brodycj commented 7 years ago

In case of issues with pre-populated databases: please start with https://github.com/brodybits/cordova-sqlite-ext-bootstrap-starter-app which has CC0 (public domain) license. In case of Ionic please try https://github.com/iursevla/ionic2-PreDB (Unlicense - also public domain, thanks @CampaUTN for pointing it out) or one of the other Ionic starters already documented.

IMPORTANT NOTE: Beware that the pre-populated database will NOT be copied if database with the same name was already copied or initialized. This is a common pitfall that was already documented.

ergurjeet commented 7 years ago

@sofarojo the example given on https://ionicframework.com/docs/native/sqlite/ with additional setting of createFromLocation:1 with https://github.com/litehelpers/cordova-sqlite-ext plugin is working for me on Android. @brodybits, thanks for the links, I will give it a try. In IOS, it's stuck at "new transaction is waiting for open operation". Even tried (window as any).sqlitePlugin.selfTest(function() { console.log('SELF test OK'); }); console.log('Test executed'); (after device ready) and echoTest, but 'SELF test ok' was never printed in the console. Also, tried uninstalling and installing the plugins several times.

sofarojo commented 7 years ago

@brodybits @ergurjeet Thank you very much!!, finally It worked. I updated my project to the latest version of angular and ionic. I made some changes in my data service thanks to this guy nicobytes [https://github.com/ion-book/demo107]