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 ?
Asked
Active
Viewed 1,080 times
1 Answers
1
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)
-
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 Mar 11 '10 at 01:02
-
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 Mar 11 '10 at 17:14
-
and have you found a function, that allows you to open database from a stream? – fazo Mar 11 '10 at 22:16
-
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 Mar 12 '10 at 11:09