Skip to content

net.sqlcipher.database.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
SyllaJay opened this issue Sep 26, 2016 · 6 comments

Comments

@SyllaJay
Copy link

I got “net.sqlcipher.database.DatabaseObjectNotClosedException” frequently. My app use "greendao-encryption:2.2.2" and "sqlcipher:3.5.4".
I saw #176 . Anyone can help please?

Releasing statement in a finalizer. Please ensure that you explicitly call close() on your cursor: INSERT OR REPLACE INTO "Session" ("_id","SESSION_KEY","TALK_ID","CREATED","UPDATED","COLOR","LAST_VI
net.sqlcipher.database.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
at net.sqlcipher.database.SQLiteCompiledSql.(SQLiteCompiledSql.java:62)
at net.sqlcipher.database.SQLiteProgram.(SQLiteProgram.java:103)
at net.sqlcipher.database.SQLiteStatement.(SQLiteStatement.java:39)
at net.sqlcipher.database.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1556)
at de.greenrobot.dao.database.EncryptedDatabase.compileStatement(EncryptedDatabase.java:66)
at de.greenrobot.dao.internal.TableStatements.getInsertOrReplaceStatement(TableStatements.java:67)
at de.greenrobot.dao.AbstractDao.insertOrReplace(AbstractDao.java:335)
..... Our code just call insertOrReplace ......

@theBlbDan
Copy link

Not seeing your code, I can only make assumptions. I found it best to extend SQLiteOpenHelper and only bother closing cursors when I'm done with them. Due to device rotation recycling the app, I gave up on managing the DB file closure myself and decided to let the OS and SQLiteOpenHelper class deal with that.

Here's a good resource to look over Local Databases with SQLiteOpenHelper.

@developernotes
Copy link
Member

Hi @SyllaJay

In conjunction with @theBlbDan's response, it is quite difficult to determine the cause of the error with the information provided. Also, it appears you are utilizing a third-party database library on top of SQLCipher for Android. Are you able to recreate an the behavior with the SQLCipher for Android test suite? Additional information with an isolated scenario would be beneficial in debugging this situation. Thanks!

@SyllaJay
Copy link
Author

Thanks for response.
I just used greenDAO and Sqlcihper, refer to http://greenrobot.org/greendao/documentation/database-encryption/

Code snippet:
ps: openHelper is instance of "de.greenrobot.dao.database.EncryptedDatabaseOpenHelper"

public void batchInsertOrUpdateSession(List entityList) {
Database db = openHelper.getWritableDatabase(mKey);
DaoMaster daoMaster = new DaoMaster(db);
DaoSession daoSession = daoMaster.newSession();
SessionDao dao = daoSession.getSessionDao();
dao.insertOrReplaceInTx(entityList);
}

@developernotes
Copy link
Member

Hello @SyllaJay

It appears your issue may be with greenDAO not closing the cursor. In your example, you are just getting a database connection from SQLCipher for Android, but then you pass it off to the greenDAO code for all other operations. You may wish to reach out to them for further details.

@SyllaJay
Copy link
Author

Thank you @developernotes . I'm working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@developernotes @SyllaJay @theBlbDan and others