views:

154

answers:

1

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 ?

+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
yes, but how do I locate that file?
wuntee
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
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
and have you found a function, that allows you to open database from a stream?
fazo
no, have not found the answer yet...
wuntee
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