Connect to existing SQLite database file

10,195 views
Skip to first unread message

Xevro

unread,
Apr 11, 2011, 4:36:36 AM4/11/11
to phonegap
Hello,

i like to connect to an existing SQLite database file on a Android
smartphone with PhoneGap database connector but i have not found,
where i had to put the sqlite database file. Is it possible to connect
to an existing database file or must i create the database on first
launch of the application on the device? The database example on
PhoneGap Documentation only shows how get access to an database which
was created in the application itself.

Any suggestions will be welcomed.
thanks for your help

bitfool

unread,
Apr 11, 2011, 12:59:56 PM4/11/11
to phonegap
There are previous posts on this and related topics, like this one
from 2009:
http://groups.google.com/group/phonegap/browse_thread/thread/ca6c85f7d6c3976c/1195990551444915
I haven't researched it further, but it may help you get started.
Paul

Xevro

unread,
Apr 12, 2011, 1:52:38 AM4/12/11
to phonegap
thanks for help but the way you show me is only for iphone. Or can i
use this for android too? I haven`t found a way connecting a excisting
database on android. Have anybody a solution?

On 11 Apr., 18:59, bitfool <paul.d.how...@gmail.com> wrote:
> There are previous posts on this and related topics, like this one
> from 2009:
>  http://groups.google.com/group/phonegap/browse_thread/thread/ca6c85f7...

Mark C

unread,
Apr 22, 2011, 6:51:54 PM4/22/11
to phonegap
I would dearly love to know how to do this as well, anyone?

On Apr 12, 6:52 am, Xevro <ericdiekm...@googlemail.com> wrote:
> thanks for help but the way you show me is only for iphone. Or can i
> use this forandroidtoo? I haven`t found a way connecting a excistingdatabaseonandroid. Have anybody a solution?
>
> On 11 Apr., 18:59, bitfool <paul.d.how...@gmail.com> wrote:
>
> > There are previous posts on this and related topics, like this one
> > from 2009:
> >  http://groups.google.com/group/phonegap/browse_thread/thread/ca6c85f7...
> > I haven't researched it further, but it may help you get started.
> > Paul
>
> > On Apr 11, 4:36 am, Xevro <ericdiekm...@googlemail.com> wrote:
>
> > > Hello,
>
> > > i like to connect to anexistingSQLitedatabasefile on aAndroid
> > > smartphone with PhoneGapdatabaseconnector but i have not found,
> > > where i had to put the sqlitedatabasefile. Is it possible to connect
> > > to anexistingdatabasefile or must i create thedatabaseon first
> > > launch of the application on the device? Thedatabaseexample on

KenCorbettJr

unread,
Apr 23, 2011, 3:49:00 PM4/23/11
to phonegap
I'm not sure it is even possible. To my understanding most people
have to create / fill the database from within their app which can be
a tricky thing. To make this an easier process I created a small
javascript library called html5sql (https://github.com/KenCorbettJr/
html5sql). It allows you to batch process sql statements in
sequence. So essentially you can take your existing sqlite database
that you want to ship. From the comand line dump the tables. Throw
that and html5sql into your app and you will be able to easily
recreate your database. If you want more info check out the
documentation on the git hub page.

Ken Corbett

Mark C

unread,
Apr 24, 2011, 8:35:44 AM4/24/11
to phonegap
Thanks for the reply, html5sql looks like it could be pretty handy.

I had just assumed a solution similar to the ios solution was
possible, that a pre-made db could be placed in the location where it
would be created within the app.

I'm gonna try creating and adding the data with javascript, theres a
few hundred rows so hopefully that won't cause any problems.

Dennis Z Jiang

unread,
Apr 24, 2011, 6:14:39 PM4/24/11
to phonegap
There is a solution for Android, and it is similar to the iphone one.
Just include the "Databases.db" and "0000000000000001.db" files in
your project's "assets" folder, then at run time copy them over to the
below locations.

String DB_PATH1 = "/data/data/" +
this.getClass().getPackage().getName() + "/app_database/Databases.db";
String DB_PATH2 = "/data/data/" +
this.getClass().getPackage().getName() + "/app_database/
file__0/0000000000000001.db";

Note that the location is actually specified by phonegap. Somewhere in
the DroidGap.java source file, you can find the following code:

// Enable database
Package pack = this.getClass().getPackage();
String appPackage = pack.getName();
WebViewReflect.setStorage(settings, true, "/data/data/" +
appPackage + "/app_database/");

Mark C

unread,
Apr 25, 2011, 8:55:13 AM4/25/11
to phonegap
Excellent, I will be giving this ago. Thanks.

אבינועם

unread,
Apr 26, 2011, 4:30:22 AM4/26/11
to phon...@googlegroups.com
Dennis Z Jiang is your solution works with big DB like 5MB ?

--
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

Dennis Z Jiang

unread,
Apr 26, 2011, 9:37:59 AM4/26/11
to phonegap
My db is not 5MB big, but I don't know why bigger db will not work. I
guess you can try it out and report back.
> > For more info on PhoneGap or to download the code go towww.phonegap.com- Hide quoted text -
>
> - Show quoted text -

אבינועם

unread,
May 1, 2011, 8:02:51 AM5/1/11
to phon...@googlegroups.com
OK,
What i manage to do is build a native db plugin.
that works with regular android db's.
and can query all db sizes and return Jason Objects.

And in order to load a big file in android you need to
1) slice it in to sizes of 1.5m each of raw files
2) on load create db if needed
3) insert the raw data in db


i used this articles together to get it working :
http://androidblogger.blogspot.com/2009/05/how-to-ship-application-with-pre-baked.html
http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/comment-page-1/

Dennis Z Jiang

unread,
May 1, 2011, 12:11:10 PM5/1/11
to phonegap
Interesting. I was not aware that the SQLite db on the browser has a
size limit.

The first article on your links says that if you put the db files on
the assets folder, there will be not size limit on the files. Why
there is still the need to slice it into 1.5m apiece?

On May 1, 8:02 am, אבינועם <avinoa...@gmail.com> wrote:
> OK,
> What i manage to do is build a native db plugin.
> that works with regular android db's.
> and can query all db sizes and return Jason Objects.
>
> And in order to load a big file in android you need to
> 1) slice it in to sizes of 1.5m each of raw files
> 2) on load create db if needed
> 3) insert the raw data in db
>
> i used this articles together to get it working :http://androidblogger.blogspot.com/2009/05/how-to-ship-application-wi...http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-and...
> > towww.phonegap.com-Hide quoted text -

Sangari V

unread,
Apr 23, 2012, 7:25:26 AM4/23/12
to phon...@googlegroups.com
hai,

 how to load a existing sqllite database in phonegap for  both ios and android in common?


Regards,
sangari.v

Chris Brody

unread,
Apr 24, 2012, 1:08:40 AM4/24/12
to phon...@googlegroups.com
The plugin https://github.com/chbrody/Cordova-SQLitePlugin should overcome these limits.
> > > > phonegap+unsubscribe@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
> > towww.phonegap.com-Hide quoted text -
>
> > > - Show quoted text -
>
> > --
> > 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+unsubscribe@googlegroups.com

Raghav Sharma

unread,
Dec 16, 2014, 1:26:31 AM12/16/14
to phon...@googlegroups.com, ericdi...@googlemail.com
hello, 
i have a question about phonegap with sqlite database.I have prepopulated database in my assets folder "myDB.db" and my problem is i want to access database direct from assets folder into phonegap. I don't want to copy into sd card or don't use external database. 
  Regards
Reply all
Reply to author
Forward
0 new messages