5

There seems to be a 1MB limit on Android's Cursor Window size which limits the ability to read BLOBs from SQLite. I know you may say we should not store BLOBs in database but by definition, BLOB is considered a Binary Large Object and if there was no need to store them in database, there was no need to implement such object type in any database engines.

The 1 MB limit on the implementation of Cursor however, seems to be insufficient in almost all cases. I need to store my binary data for valid reasons in SQLite database and they are well over 1 MB. SQLite is capable of handling BLOBs perfectly since the C API is working perfectly fine in Xcode (iPhone platform) to retrieve large objects without any issues.

I'm wondering if we can possibly access the BLOB data in Android without using cursors. I am thinking of a lower level access to Sqlite in Java. Any suggestions?

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Bms270
  • 1,586
  • 15
  • 18

2 Answers2

7

As CL mentioned, using NDK is indeed a way to access Sqlite natively via C language in Java language. However I realized it could get really messy if I wanted to write a custom wrapper myself and try to access the functions in Java.

After searching around, I came across a brilliant open source project called Sqlite4java which is a tight wrapper around Sqlite, compiled to use on various platforms including Android. This library allows you to interact with Sqlite without using Android Cursor which removes the limitations.

I am able to retrieve 20 MB of Blob in 480 milliseconds. This is even faster than reading a small record from Sqlite via Cursors. I believe this can be used to enhance any query to Sqlite by skipping the use of Cursor. Here's the link to this great library: http://code.google.com/p/sqlite4java/

Namphibian
  • 12,046
  • 7
  • 46
  • 76
Bms270
  • 1,586
  • 15
  • 18
  • In my case I have a lot of blobs with sizes between 10kb to 1MB. Will using mentoined NDK (sqlite4java) give me better performace of reading my blobs insteed of using the cursor ? – mcfly soft Feb 21 '14 at 07:54
0

Android's Java API always has the 1 MB limit.

You should not store BLOBs of that size in the database; the file system is more efficient at handling them.

If you really want to use BLOBs, you have to go through the NDK to access the C API directly.

CL.
  • 173,858
  • 17
  • 217
  • 259
  • 3
    Thanks, I guess I need to look into NDK. The advise of not using BLOBs is not always a correct advise. If the database engine supports BLOB data type and can handle it, then I do not understand why we should try to justify the deficiency of the SDK by advising against using the BLOB where it is actually well supported by the SQLite engine. – Bms270 Jun 25 '13 at 19:11
  • Large blobs are *not* supported by the Android Java API. – CL. Jun 26 '13 at 06:07
  • Correct. I am still trying to accomplish this via NDK. I will update here once I have a workaround. – Bms270 Jun 26 '13 at 13:44