How to use an embedded (application resource) DB?

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

How to use an embedded (application resource) DB?

Postby Sparkletron » Fri Nov 07, 2008 10:00 pm

Android SDK includes various classes to work with SQLite. The problem is that there doesn’t seem to be any way to use a database embedded in an application. Indeed, the only way I’ve been able to access any embedded resource is by using the following mechanism...

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. InputStream inputStream = getResources().openRawResource(R.raw.<someResource>);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


This returns an InputStream, which can then be used to pull in the resource. Unfortunately, the SQLiteDatabase factory methods expect database file references in the form of file system paths...

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. SQLiteDatabase database = SQLiteDatabase.openDatabase("/path/to/database/file", null, SQLiteDatabase.OPEN_READONLY);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


As far as I can tell, there is no way to supply a file path that leads to the application’s own file space or context. There is no way to load an embedded SQLite database except perhaps by doing something kludgy, like maybe reading it in using the aforementioned InputStream, then writing it out some place where a file path reference will work (e.g., "/data/data/<package_name>/databases"), then supplying said reference to the SQLiteDatabase factory methods.

Being able to include resource files and fully access them is basic stuff. So far this is the second crippling resource limitation I’ve seen (the first one being a one-meg file limit imposed by UNCOMPRESS_DATA_MAX).
Sparkletron
Developer
Developer
 
Posts: 26
Joined: Tue Nov 04, 2008 6:17 am

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 1 guest