yangblocker / GreenDao-SQLCipher

greenDao support for SQLCipher
42 stars 20 forks source link

Cursor not closed #1

Closed McPo closed 9 years ago

McPo commented 10 years ago

When using this application Ive been receiving errors in the logs regarding finalising cursors by closing them. The application still works unhindered and the database is encrypted.

07-17 11:23:24.985  21695-21708/saltdna.com.saltim E/Cursor﹕ Finalizing a Cursor that has not been deactivated or closed. database = /data/data/saltdna.com.saltim/databases/app_database, table = null, query = SELECT T.'_id',T.'ID',T.'NAME'' FROM LIST T  WHERE T.'NAME' LIKE ? ORDER BY T.'NAME'
net.sqlcipher.database.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
        at net.sqlcipher.database.SQLiteCursor.<init>(SQLiteCursor.java:217)
        at net.sqlcipher.database.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:53)
        at net.sqlcipher.database.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1450)
        at net.sqlcipher.database.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1419)
        at de.greenrobot.dao.query.Query.listLazy(Query.java:131)
        at de.greenrobot.dao.query.QueryBuilder.listLazy(QueryBuilder.java:383)
yangblocker commented 10 years ago

hi, you used listLazy when you query your database? if you used that, you MUST close the cursor by yourself.some document about greendao Queries is here.

McPo commented 10 years ago

Hi ywenblocker,

While is should still close it myself. GreenDao is also supposedly meant to auto-close them for me, under specific condition.

"The cached lazy list from listLazy() and the lazy iterator from listIterator() closes the cursor automatically, once all elements are accessed or traversed. However, it’s your job to call close() if the list processing stops prematurely."

I know my app reaches this condition as swapping out the sqlcrypt version for the non-sqlcrypt version, no errors appear in the log. So there looks like there's an unattended divergence from base, there also doesn't appear to be any recent bug fixes on main to explain the inconsistency.