7

It appears that Cursors in android can only hold up to 1 MB of data.

What would be the most efficient way to pull the maximum number of rows from a table in a SQLite database that stays under the 1 MB limit?

General Grievance
  • 4,555
  • 31
  • 31
  • 45
  • The best way I have come up with so far is to sample a few rows and "estimate" how many rows you can pull. You just have to make sure you never go over the 1MB limit. – zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz Jun 22 '12 at 18:38
  • the best method is to use the concept of paging, that means get the data from database in parts ,getting rows ten by ten and clearing the cursor before the next retrieving from database. – deepak825 May 06 '13 at 12:57

2 Answers2

0

I don't think there's a hard and fast way to determine the right limit, but I looked in the CursorWindow documentation and found that copyStringToBuffer (int row, int column, CharArrayBuffer buffer) seems promising as CharArrayBuffer has a integer field called sizeCopied and the method copyStringToBuffer takes the text at the specified row and column. Maybe you can get the size from the buffer and add for each row and column you have? If you're using SQLiteCursor, you can use setWindow(CursorWindow window) to set your own window.

John61590
  • 1,106
  • 1
  • 13
  • 29
-1

You can put LIMIT clause, so that rows are fetched in parts.

Programmer
  • 5,360
  • 10
  • 37
  • 61