Deploying sqlite database

232 views
Skip to first unread message

Joshua Grauman

unread,
Feb 18, 2013, 11:46:00 AM2/18/13
to andro...@googlegroups.com
Hello all,

I know I've seen this question asked before, but I haven't found a definitive answer yet. Does necessitas work with the DEPLOYMENTFOLDERS directive in qmake .pro files or something like this? I'd like to deploy an already created/populated sqlite database file, without having to include it in a resource file or in assets as that would double the amount of space I'm using on the device. Is there any way to deploy a sqlite file (or any file for that matter) to a read/write location, without also having to have it in a read-only location first (like assets or qrc)? Thanks!

Josh

Sebastian Diel

unread,
Feb 18, 2013, 1:43:24 PM2/18/13
to andro...@googlegroups.com
Hi Josh,

to my knowledge the way via asset/rsc and copying on first start is the
only possible way.

If I understand the Android system correctly, nothing else makes sense
anyway, as the apk
has to be kept (in *full* beauty!) in a separate folder - a folder the
app cannot write to
nor delete/move from.

IMHO there is no Android way to cut the database file from the apk - it
reside be in the apk, where
it can't be opened for writing. This seems to be an Android system
decision for me, not a lack of
Necessitas' possibilities, so I don't expect this to possibly be changed
in future versions.

Though it would be cool to automate the copying process so that you
could use the
deploymentfolder syntax like on other platforms, but under the hood I
think it would have to
do the same thing:
copy (not move) the data into a writeable folder, thus duplicating the
amount of space needed.

The only other possibility I see would be to dynamically load the db
from the net on first start.
Thus it would not be in the apk in the first place - but adblocker or
lack of net access can get
you into trouble there, of course.

All this said, I am *not* expert enough to be sure if the above is
correct. I would love to read a
comment about this from the wizards on this list.

Best regards,
Sebastian
> --
> You received this message because you are subscribed to the Google
> Groups "android-qt" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to android-qt+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Joshua Grauman

unread,
Feb 18, 2013, 3:10:06 PM2/18/13
to andro...@googlegroups.com
Makes sense. Thanks for the clarification. I'd love to hear if any 'wizards' can confirm this as well. I'll have to think about download on first run, that may be an option. Can anyone tell me where I should copy my data files to from qrc or assets? Is there a standard location/directory to put (writable) data files? Thanks!

Josh

Joshua Grauman

unread,
Feb 18, 2013, 3:13:28 PM2/18/13
to andro...@googlegroups.com
I just thought of another question too. What if I separate my sqlite database into read-only tables (most of it), and writable tables. If I put the read-only database file in the assets, can sqlite read it from there, or is it a problem that assets are read-only (even though I don't write to that database, does sqlite need to be able to write?)? Thanks again!!!

Josh

Scott Aron Bloom

unread,
Feb 18, 2013, 3:47:52 PM2/18/13
to andro...@googlegroups.com

It will depend on your SQL settings (which have changed from version to version of SQLITE + Qt)

 

When they had no locking, you could get away with readonly, but now they usually lock, and need to be able to create the .lck file


Scott

jenna

unread,
Feb 18, 2013, 6:21:20 PM2/18/13
to andro...@googlegroups.com
As far as choosing to store your database in qrc or assets before copying it to a writable location, I think the better choice is to put it in your assets.  If you data is stored in qrc, then it is a piece of your compiled binary.  This means that it increases the size of your apk (your lib.XXX.so is bigger) and increases the amount of space your project takes up in ram.  Even after you copy your data to a writable location, you still have a copy of it in ram that your can't modify.  The befit is that your file is always fully in ram for you, so reading it is really fast.  If you store your file as an asset, it is stored as a file in your apk (zip file).  It does not increase the size of your libXXX.so, but it does still increase the size of your apk stored on the device.  

So, both options leave you with a bigger apk that contains, in some form, a copy of your database that you cannot modify.  One of the options also makes your app use more ram to store another copy of the database in ram that still cannot be modified.

Sebastian Diel

unread,
Feb 18, 2013, 7:00:21 PM2/18/13
to andro...@googlegroups.com
Hi,

I do it like this:
QFile::copy("assets:/einstellungen.xmlp",QDir::currentPath()+"/einstellungen.xmlp");
With root access you can then find it in /data/data/org.kde....(yourProg)/files

But be careful: you still cannot write, because the permissions have been copied, too!
QFile::setPermissions(QDir::currentPath()+"/einstellungen.xmlp",QFile::ReadOwner|QFile::WriteOwner);
finally does the trick.

When copying folders, be aware that there is still a bug:
QFileInfoList does NOT give you any folders, at least it didn't for me:

QFileInfoList
fiList=sourceDir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst);
works on Windows, on Android there are no dirs in the list. At least not when copying from assets, I didn't test this somewhere else, actually.

Best regards,

Sebastian

Joshua Grauman

unread,
Feb 19, 2013, 1:30:48 AM2/19/13
to andro...@googlegroups.com
Thanks so much, that's super helpful! Is there a way to tell qmake to put files in the assets directory automatically? Or how do you normally do that?

Josh

Sebastian Diel

unread,
Feb 19, 2013, 3:35:49 PM2/19/13
to andro...@googlegroups.com
Am 19.02.2013 07:30, schrieb Joshua Grauman:
> Thanks so much, that's super helpful! Is there a way to tell qmake to
> put files in the assets directory automatically? Or how do you
> normally do that?
Within your development folder you'll find \android\assets - just put
the file(s) into that folder.

Sebastian

Ken

unread,
Jul 9, 2013, 1:59:57 AM7/9/13
to andro...@googlegroups.com
You may have seen this or not, but what dan recommends has helped me.
Reply all
Reply to author
Forward
0 new messages