Retrieve large blob from Android sqlite database

后端 未结 2 772
心在旅途
心在旅途 2020-11-29 05:36

I stored chunks of binary data (protobufs) in the sqlite database of an Android app without realizing that Android\'s Cursor can only hold a maximum of 1MB of d

2条回答
  •  天涯浪人
    2020-11-29 06:02

    You can read large blobs in pieces. First find out which ones need this treatment:

    SELECT id, length(blobcolumn) FROM mytable WHERE length(blobcolumn) > 1000000
    

    and then read chunks with substr:

    SELECT substr(blobcolumn,       1, 1000000) FROM mytable WHERE id = 123
    SELECT substr(blobcolumn, 1000001, 1000000) FROM mytable WHERE id = 123
    ...
    

    You could also compile your own copy of SQLite and access either the BLOB stream I/O functions or the normal query functions of the C API with the NDK, but that would be too complex in this case.

提交回复
热议问题