3

In database file (in assets) I need read some date without copying this databse on device. I didnt find answer in google for correct work.

Is it possible?

MyNameIs
  • 832
  • 1
  • 8
  • 19

3 Answers3

3

SQLite needs a local file, not merely an InputStream, in order to work.

Either:

  • Use SQLiteAssetHelper and copy the data to a local file, or

  • Do not use SQLite as the storage format, but instead use something else for which you have an InputStream-friendly parser (e.g., JSON, using Gson)

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
2

No, you can not do that because all the assets are compiled in a binary form and android preserve the names of all the asset's file from which it can access the file at runtime...! Project Resources, Please see the main/assets on the link

Android SQLiteDatabaseHelper needs some kind of InputStream...!

Alternatives:

  • You can copy the database from your assets directory to the android app directory. For refference see this link...!

  • You can copy the database from assets to sdcard and then access it....! Please see this link..!

  • You can use a JSON, XML or GSON format intead of SQLITE (not recommended)

Community
  • 1
  • 1
Arsal Imam
  • 2,882
  • 2
  • 24
  • 35
0

i was thinking about using an input stream since we can point it to an asset, but it turns out the lowest level of db call is native accepting an os file. therefore, copying to local should be the only option even it is read-only

nativeOpen

DayDayHappy
  • 1,679
  • 1
  • 15
  • 26