I have a database that I have already populated locally. I want to bundle it with my applications and access it at runtime (never want to re-write it anywhere, nor write to the database, simply read). What is the path of a file that I have added to the bundle? And, can i use that path with a SQLiteDatabase.openDatabase ?
views:
154answers:
1
+1
A:
well - you answered your own question
static SQLiteDatabase openDatabase(String path, SQLiteDatabase.CursorFactory factory, int flags)
Open the database according to the flags OPEN_READWRITE OPEN_READONLY CREATE_IF_NECESSARY and/or NO_LOCALIZED_COLLATORS.
looks like you can
(of course you don't call it with CREATE_IF_NECESSARY, but OPEN_READONLY)
fazo
2010-03-11 00:12:08
yes, but how do I locate that file?
wuntee
2010-03-11 00:37:50
here:http://stackoverflow.com/questions/2364185/android-read-a-gzip-file-in-the-assets-folder/2397568#2397568 just pack your database as resources.zip and put it to res/raw; then you can access it as told in provided link
fazo
2010-03-11 01:02:26
yes, but then i can access it as an input stream - i dont want to re-write it out, then open it with the SQLiteDatabase.openDatabase. is there a way to open a database from a stream?
wuntee
2010-03-11 17:14:33
and have you found a function, that allows you to open database from a stream?
fazo
2010-03-11 22:16:36
no, have not found the answer yet...
wuntee
2010-03-12 04:28:25
maybe, because there isn't such a function? none of openDatabase have stream as parameter... besides, don't you think, that sqlite has to load a database first to know what it has?
fazo
2010-03-12 11:09:21