1

My question is very much similar to this one but slightly different. I get the following error when I simply try to query everything in my table that has been encrypted by SQLCiper.

 12-29 11:37:54.329: E/Cursor(10837): Finalizing a Cursor that has not been deactivated or closed. database = /data/data/com.company.myapp/databases/data, table = data_table, query = SELECT rowid, data FROM data_table
 12-29 11:37:54.329: E/Cursor(10837): info.guardianproject.database.sqlcipher.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
 12-29 11:37:54.329: E/Cursor(10837):   at info.guardianproject.database.sqlcipher.SQLiteCursor.<init>(SQLiteCursor.java:225)
 12-29 11:37:54.329: E/Cursor(10837):   at info.guardianproject.database.sqlcipher.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:53)
 12-29 11:37:54.329: E/Cursor(10837):   at info.guardianproject.database.sqlcipher.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1410)
 12-29 11:37:54.329: E/Cursor(10837):   at info.guardianproject.database.sqlcipher.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1289)
 12-29 11:37:54.329: E/Cursor(10837):   at info.guardianproject.database.sqlcipher.SQLiteDatabase.query(SQLiteDatabase.java:1243)
 12-29 11:37:54.329: E/Cursor(10837):   at info.guardianproject.database.sqlcipher.SQLiteDatabase.query(SQLiteDatabase.java:1325)
 12-29 11:37:54.329: E/Cursor(10837):   at com.company.appName.DatabaseManager.queryAllItems(DatabaseManager.java:105)

I thought that this error would only happen if I forgot to close the Cursor after I was done using it but it seems that I'm getting this error even before I'm able to start using it.

Here's the code that's in the queryAllItems() method:

public Cursor queryAllItems() {
    return database.query(DATABASE_TABLE, new String[] {KEY_ID, KEY_DATA}, null, null, null, null, null);
}
Community
  • 1
  • 1
Brian
  • 7,955
  • 16
  • 66
  • 107
  • 1
    The error indicates that the `Cursor` "was opened here". To me, that means you successfully called `queryAllItems()`, but never then closed the `Cursor`, and it is telling you where you created the `Cursor` in the first place. – CommonsWare Dec 29 '11 at 19:55
  • You're totally right, I put in a couple of debug markers and noticed that the error was happening after all the querying was done. I guess I was misled by that stack trace. – Brian Dec 29 '11 at 20:30

2 Answers2

1

I was misled by the stack trace and it appeared that I just need to call Cursor.deactivate() and Cursor.close() after all my operations on the query were done.

Brian
  • 7,955
  • 16
  • 66
  • 107
0

After creating cursor, if you call startManagingCursor(c); will resolve the issue. Here 'c' is cursor reference.

kosa
  • 65,990
  • 13
  • 130
  • 167