question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No way to reopen closed database

See original GitHub issue

DBFlow Version: 3.1.1 Issue Kind : Bug Description:

FlowSQLiteOpenHelper#getDatabase always return same SQLiteDatabase. I think FlowSQLiteOpenHelper#getDatabase should work like SQLiteOpenHelper#getWritableDatabase: if the database is closed it will create new database instead.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
CapnSpellcheckcommented, Oct 22, 2017

@douo What about addressing the cached prepared statements? ModelAdapter.java @ 4.0.0-beta3:

    /**
     * @return The pre-compiled insert statement for this table model adapter. This is reused and cached.
     */
    public DatabaseStatement getInsertStatement() {
        if (insertStatement == null) {
            insertStatement = getInsertStatement(
                    FlowManager.getDatabaseForTable(getModelClass()).getWritableDatabase());
        }

        return insertStatement;
    }

I still got a stack trace

                                 java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed.
                                     at android.database.sqlite.SQLiteConnectionPool.throwIfClosedLocked(SQLiteConnectionPool.java:962)
                                     at android.database.sqlite.SQLiteConnectionPool.waitForConnection(SQLiteConnectionPool.java:599)
                                     at android.database.sqlite.SQLiteConnectionPool.acquireConnection(SQLiteConnectionPool.java:348)
                                     at android.database.sqlite.SQLiteSession.acquireConnection(SQLiteSession.java:894)
                                     at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:786)
                                     at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
                                     at com.raizlabs.android.dbflow.structure.database.AndroidDatabaseStatement.executeInsert(AndroidDatabaseStatement.java:77)
                                     at com.raizlabs.android.dbflow.sql.saveable.ModelSaver.insert(ModelSaver.java:104)
                                     at com.raizlabs.android.dbflow.sql.saveable.ModelSaver.save(ModelSaver.java:48)
                                     at com.raizlabs.android.dbflow.sql.saveable.ModelSaver.save(ModelSaver.java:31)
                                     at com.raizlabs.android.dbflow.structure.ModelAdapter.save(ModelAdapter.java:102)
                                     at com.raizlabs.android.dbflow.structure.BaseModel.save(BaseModel.java:62)

See how we use the cached statement, and in SQLiteStatement it goes to SQLSession. So the cached session is bad – we need to clear all cached statements. Is there a way to do this? I don’t know if this has been updated post beta3, unfortunately, I’m stil lon 4.0.0.

0reactions
CapnSpellcheckcommented, Oct 23, 2017

Best idea for how to work around. Critiques? Suggestions?

// workaround for https://github.com/Raizlabs/DBFlow/issues/925 my comment (CapnSpellcheck)
            val insertStatementField = ModelAdapter::class.java.getDeclaredField("insertStatement")
            insertStatementField.isAccessible = true
            val compiledStatementField = ModelAdapter::class.java.getDeclaredField("compiledStatement")
            compiledStatementField.isAccessible = true

            val adapters = FlowManager.getDatabase(Database::class.java).modelAdapters
            for (mad in adapters) {
                Log.d(tag_, "Resetting model adapter ${mad.javaClass.simpleName}")
                insertStatementField.set(mad, null)
                compiledStatementField.set(mad, null)
            }
Read more comments on GitHub >

github_iconTop Results From Across the Web

python sqlite3 reopen database - Stack Overflow
How do I open the database again, after I closed it? I was thinking closing it and then reopening would be a good...
Read more >
how to reopen a closed connection? - Oracle Communities
If I'm working on a worksheet, and I lose connection, how do I reopen it? I try running my code, and the Query...
Read more >
How To Reopen Closed Tabs and Restore Webpages - Indeed
2. With keyboard shortcuts. The shortcut to reopen closed tabs is Ctrl+Shift+T on a Windows operating system and Command+Shift+T on macOS.
Read more >
Cannot access or reopen a database which is "Auto Closed"
If it is not possible to use ADS to open an auto-closed database. Is there any other way which works without admin rights?...
Read more >
Must close and reopen current database notification
"You must close and reopen the current database for the specified option to take effect." This only occurs in one of my DBs...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found