Ionic and cordova-sqlite-ext

I’m trying to update a project from Ionic 2 to Ionic 3 and in this project I was using the cordova-sqlite-ext plugin with a pre-populated database stored in www folder.

To open (and create) the database, I was using:

...
this.sqlite.openDatabase({name: "data.db", location: 'default', createFromLocation: 1}).then(...
...

but the param createFromLocation: 1 doesn’t work anymore with the create method

Please, someone can suggest me how to use (if it’s possible) this cordova plugin with the last version of Ionic and Ionic Native SQLite? Thanks…

1 Like

Did you please find a solution to this?

I solved in this way. I created:

private options = { name: "data.db", location: 'default', createFromLocation: 1 };

and passed it in:

this.sqlite.create(this.options).then((db: SQLiteObject) => {...

and it seems to work perfectly. Hope it helps you!

2 Likes

works like a dream, thank you!

1 Like

You’re welcome! :slight_smile: I hope it helps all other forum users looking for this information.

@morris4ever69 I did not work completely because when I make a query the app stops, can someone help me?

What I do is create a project from scratch with the utter versions of ionic and the plugins I use, what I did was:

  • ionic start test
  • ionic cordova platform add android
  • cordova plugin add cordova-sqlite-ext --save
  • npm install --save @ionic-native/sqlite
  • In app.module.ts
    import { SQLite } from ‘@ionic-native/sqlite’; …
  • ionic generate provider database
  • This is the code I have inside the povider
  • ionic cordova run android -l -c

There are two problems:
1- My provider is never executed
Solution: I import it inside the app.component.ts
2- When the app opens, stop after reading my provider, I try without the query executeSql and it works without launching error, when I just put the executeSql stops the app, although I reopened it.
error

I hope you can please help me, thank you

I say that it did not work completely because it verifies that the database was imported correctly, since I did this:

  • adb shell
  • run-as io.ionic.starter
  • cd databases
  • sqlite3 database.db
  • select nombre from fuerzas;

If I had data in that table.

hi friends, the above code is creating new database always, its not using existing database

i get error when i try to install cordova-sqlite-ext Plugin and i can’t add a provider because im using Ionic 4
Any solution please ??