Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading a local sqlite file from phonegap

I can create a sqlite DB in phonegap/html5 via window.openDatabase. I am going to have a large amount of data, so I want to ship it with the app.

So can I store a sqlite DB somewhere, within the app (It needs to work on both iOS and Android). I particular where is the shortName.db stored when I call

var db = openDatabase(shortName, version, displayName, maxSize);

And can I pre-populate this sqlite file. (In the phonegap environment)

like image 958
agiliq Avatar asked Jun 21 '11 11:06

agiliq


3 Answers

Listed here are some solutions for iphone and android:

http://groups.google.com/group/phonegap/browse_thread/thread/5e57a728dc66a2a1?pli=1

like image 102
zanedev Avatar answered Oct 31 '22 14:10

zanedev


I've not used PhoneGap, only created HTML5 apps that use Web SQL. However, if you're asking whether you can ship an app with a pre-populated SQLite database, then yes you can. Probably the simplest approach would be to provide the table creation scripts as part of the app. When it's first fired up, you can have the scripts run, and your database will then be fully initialised.

like image 23
Ben Avatar answered Oct 31 '22 12:10

Ben


An alternative approach for deploying bulk data I came up is simply serialize it into text files and deploy the files together with the app.

You can use the File API provided by PhoneGap to load these files as strings, and parse them with Ext.util.JSON.decode().

Finally, use the MemoryProxy to integrate the decoded data with the rest of Sencha Touch and you are golden.

like image 2
Daniel Duan Avatar answered Oct 31 '22 12:10

Daniel Duan