Application with database tables that don't change

50 views
Skip to first unread message

giovanni battista lenoci

unread,
May 20, 2012, 10:28:57 AM5/20/12
to phon...@googlegroups.com
Hi, I have a web application that I want to port on phones with phonegap. Basically the application has a database of questions with true/false answer. I have about 10.000 questions on a mysqldatabase, and I want to use those question on the phonegap version of the app.

I've did a bit of experimentation on phonegab, but essentially I an a newbie. 

I've read about sqllite, but if I understood, I have to check every time I start the app if the database exists, and then if it doesn't exists I have to create it.

with pseudo code should be something like:

1. devideReady
2. connectToDb
  • A ) if exists read and use data
  • B) if doen'ts exists CREATE TABLE.... the you can proceed to A.

Assuming that the pseudocode is right, I have to include a javascript file with about 200k of sql statement even if the database was created in a previous run of the app...am I right? 

Can I place a .sql file on /assets/www/ to read from when the database doesn't exists? There's a guideline on how to manage data that will not change in the future? 

maybe I can save this dump to json file, but then I need something to query the file to extract random data or data based on relations...

any advice will be appreciated :-)



--
Giovanni Battista Lenoci - Ueppy Technical Manager    
Via Piedo 58, 23020 Tresivio (SO)
+39 347 7196482
gia...@ueppy.com - http://www.ueppy.com/

jcesarmobile

unread,
May 20, 2012, 3:29:10 PM5/20/12
to phon...@googlegroups.com
You can't use the data directly from a mysql database, but you can insert the data into a sqlite database, and get a .db from the sqlite database and prepulate it instead inserting with javascript

you can read it here

I think you can use a .db, not a .sql with a plugin

http://gauravstomar.blogspot.com.es/2011/08/prepopulate-sqlite-in-phonegap.html

Or maybe there is some plugin to store the data in a native sqlite database.

Phang Mulianto

unread,
May 20, 2012, 11:02:46 AM5/20/12
to phon...@googlegroups.com

Hi,

Sqlite db is a file,  just like mysql db. You can create the db first and import all your data from mysql to sqlite.. And put the sqlite db in your www folder or somewhere acessible by your app.

The create db in the doc is only for initialization..don't have to be that way..

And you can use your current db using webservice access by your mobile app without include your db which will take some space in user mobile limited space..

Hope help..

--
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com

Simon MacDonald

unread,
May 20, 2012, 9:35:06 PM5/20/12
to phon...@googlegroups.com
Going the pre-populated DB route is probably the best way to go if you
have 10,000 entries. If you want to do a straight .sql file you can
use HTML5SQL.js. I wrote up a little post on it:

http://simonmacdonald.blogspot.ca/2011/12/on-fourth-day-of-phonegapping-creating.html

Simon Mac Donald
http://hi.im/simonmacdonald

giovanni battista lenoci

unread,
May 21, 2012, 9:04:16 AM5/21/12
to phon...@googlegroups.com
Thank you all guys :-)

giovanni battista lenoci

unread,
May 21, 2012, 11:35:45 AM5/21/12
to phon...@googlegroups.com

2012/5/20 jcesarmobile <jcesar...@gmail.com>

You can't use the data directly from a mysql database, but you can insert the data into a sqlite database, and get a .db from the sqlite database and prepulate it instead inserting with javascript

you can read it here

I think you can use a .db, not a .sql with a plugin

http://gauravstomar.blogspot.com.es/2011/08/prepopulate-sqlite-in-phonegap.html

Or maybe there is some plugin to store the data in a native sqlite database.

Hi jcesar, I like your approach, but I can't understand a step.

Now I don't have a db, I have created one from a mysqldump using this:


I've tried opening the dump.db created file with the firefox sqllite extension and I can see my data.

Looking a the blog post you've linked it talks about 2 files, (generated from the first run of an app?) 

Can you help me? 


jcesarmobile

unread,
May 21, 2012, 12:31:57 PM5/21/12
to phon...@googlegroups.com
Read first the link Simon posted, that is the way to read the external file and insert the data into the app db. (Only executed the first time)

Once it is inserted you can do what I said, but only if you don't want the users to wait while the data is inserted (with 10000 entries I supose it will take a while), if you don't mind, Simon method will be enough


El domingo, 20 de mayo de 2012 16:28:57 UTC+2, Giovanni Battista Lenoci escribió:
Reply all
Reply to author
Forward
0 new messages