Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6558943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:15:42+00:00 2026-05-25T13:15:42+00:00

When I get a Cursor back from a sqlite DB query in Android it

  • 0

When I get a Cursor back from a sqlite DB query in Android it seems to contain a fixed number of rows that does not change regardless of what happens to the DB. If, for example, some of the rows are deleted while the Cursor is open I can still reference rows that have been deleted. This is nice, but how does it work?

One guess might be that sqlite knows I have a Cursor that is pointing to that row and so keeps a copy of the old data around. But what if I had a million rows, deleted them and replaced them with a million different rows, seems like a lot of data to cache!

UPDATE:

I am now thinking that this caching we see in Android isn’t really bullet-proof and isn’t part of SQLite. I created a test which builds a database with 1,000,000 rows in it, then I queried the db printed out some results and left the cursor open, next I deleted half the rows, finally I tried to access the cursor that I left open and the result is a crash:

04-05 18:17:16.141 E/AndroidRuntime(19655): java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
04-05 18:17:16.141 E/AndroidRuntime(19655):     at android.database.CursorWindow.nativeGetLong(Native Method)
04-05 18:17:16.141 E/AndroidRuntime(19655):     at android.database.CursorWindow.getLong(CursorWindow.java:507)
04-05 18:17:16.141 E/AndroidRuntime(19655):     at android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:75)
04-05 18:17:16.141 E/AndroidRuntime(19655):     at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:220)
04-05 18:17:16.141 E/AndroidRuntime(19655):     at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:237)
04-05 18:17:16.141 E/AndroidRuntime(19655):     at com.jacob.DirectDbActivity$4.run(DirectDbActivity.java:88)

This seems like a bug in Android, since most databases are small the cache window can hold all the results but in large databases this is going to hit you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:15:43+00:00Added an answer on May 25, 2026 at 1:15 pm

    Last I checked, a cursor is a snapshot of the database based on the SQL that created it. Much like a Data set. If you change the database the cursors may not know that their snapshot is old. You can perform a re-query on the cursor to get fresh data based on the original SQL that created the cursor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a cursor containing several columns from the row it brings back that
I was trying to use the managedquery() in android to get back a cursor
Simply trying to get a cursor back for the ids that I specify. CREATE
Is it possible to get ref cursor from oracle stored procedure by using DAAB
I get a String data from Cursor, but I don't know how to convert
How to get EditText's value from sub-Activity? With a condition that if I click
The log reports that the database or cursor was not closed. I basically have
I have an activity that populates a list and does some other things from
I'm trying to get the previous tag from $('#marker').prevAll(span.curPos:eq(1)); Problem is that the HTML
I want to get the Text data value from Sub-Activity back. And everything is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.