Where to put SQLite databases on Ionic 2 RC0?

I have done exactly as you mention getting the error
Unable to execute sql-home Object(anonymous function) @ main.js:52598
message: “sqlite3_prepare_v2 failure: no such table: empdetails”

plugin details
cordova-plugin-console 1.0.5 "Console"
cordova-plugin-device 1.1.4 "Device"
cordova-plugin-splashscreen 4.0.1 "Splashscreen"
cordova-plugin-statusbar 2.2.1 "StatusBar"
cordova-plugin-whitelist 1.3.1 "Whitelist"
cordova-sqlite-ext 0.10.2 "Cordova sqlite storage plugin with extras"
ionic-plugin-keyboard 2.2.1 “Keyboard”

What version of npm, cordova and ionic do you have?

To know go to console and execute:
npm -v
ionic -v
npm cordova -v

And report back with the respective versions for each.

npm -v
4.0.3
ionic -v
2.1.14
npm cordova -v
4.0.3

it should have been cordova -v (mine is 6.4.0) but it looks like you have everything up to date.

Did you place your database file on www folder?
Are you sure your database has the table named empdetails? If you’re not sure about this use the SQLite browser to inspect your database files and respective tables.

Yes kept db folder in src folder and also in www folder both tried and am using SQLite browser to create db .i have tried with different set of db and tables no luck

Sorry for the delay but i don’t know what else you can do. Did you already fix it?

If someone is still interested, this is how i achieved:

In this case you donwloaded your db file from a server.

from the link you provided

This is what I did and got it working (which solved our purpose):

Why not place the file locally in www folder? Was there a major reason for that?

Not hating or anything just curious.

Yeah, I looked at that option. We can use that if we have prepopulated DB. That is, to package the app along with the DB. But in our case, we would download the DB from a server and save it in application or document storage folder(using cordova file transfer plugin) of the app in the device and then access this DB using SQLite plugin.

However, that prompts me another question. Can we download DB from remote server directly into www folder of the app and also can we query the DB from that location using SQLite? As I can see from documentation, SQLite has a ‘location’ property which points to application\documents directory.

hi,
Just try it:
a. uninstall/remove the app from ios simulator
b. run/build it.

It worked for me. :slight_smile:

I have this problem and think the same

Did you 1)double check the name of the database, 2) the db file is on the www folder?

Yes and then I get the error there is no table - it says it has opened it even when the name is wrong.

it says it has opened it even when the name is wrong.

Yes that is expected behaviour. If it does not find the database it tries to create one.

Ok well it is in the www folder and it doesn’t seem to be finding it.

Are you using an emulator or real device?
In any case uninstall the app from the emulator/device and then try again.

I am using the emulator

What’s the version of your Android’s emulator? Mine is 5.0.0 or 6.0.0 both working with pre-populated database.
Tonight i’ll try to create a template for ionic 2 with a pre-populated database.

I am using ios emulator

I’ve never used ios emulator so can’t really help you on the emulator.