Reputation: 8085
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);
}
Upvotes: 1
Views: 1422
Reputation: 8085
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.
Upvotes: 1
Reputation: 66637
After creating cursor, if you call startManagingCursor(c);
will resolve the issue. Here 'c' is cursor reference.
Upvotes: 0