Closed pishguy closed 7 years ago
Duplicate of #476
Thanks, can you help me on this topic: https://github.com/Raizlabs/DBFlow/issues/1097 ?
Delete as in clear?
FlowManager.getDatabase(AppDatabase.class).reset(context);
After executing FlowManager.getDatabase(AppDatabase.class).reset(context), I may get the following error if I save to a table:
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)
I get same error as previous comment.
@agrosner
this code as FlowManager.getDatabase(AppDatabase.class).reset(getBaseContext());
is deprecated, how can i resolve that?
@MahdiPishguy this is not deprecated:
FlowManager.getDatabase(AppDatabase.class).reset();
Any update on this?
"java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed."
after a reset?
Same here. got "java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed." How to solve?
Not sure how you guys solve this but I solved it with a second look at the documentation. May not be applicable to everyone but just raise it up here for reference. So I'm using databaseDefinition.executeTransacion(ITransaction)
to run my code. So after reset, as mentioned above, if I run the transaction again I'll get the IllegalStateException. The weird thing is this exception comes from inside the transaction. I actually mixed SQLite with Model together in the transaction but it seems only the Model code raise this exception. E.g. I have similar code like below in the transaction:
new ProcessModelTransaction.Builder<>((Model model, DatabaseWrapper databaseWrapper) -> {
SQLite.delete(AA_Table.class).where(AA_Table.id.in(...));
model.save();
})
The exception comes from model.save()
but not from the delete. Then I realized that in the official documentation, it should be model.save(databaseWrapper)
Not 100% sure why it's not working without passing in databaseWrapper, but my suspect is the default dbwrapper is not setup after reset. Not sure if this is a bug but from my perspective, this shouldn't happen. If I don't call reset, save without passing databaseWrapper can work perfectly. So I suggest that resetting should consider reinitialize all the resources required by model as well. Otherwise it's really hard to find the issue.
FlowManager.getDatabase(AppDatabase.class).reset();
is worked for me. Thanks @felipezf
It Performs a full deletion of this database. Reopens the {@link FlowSQLiteOpenHelper} as well. Reapplies the {@link DatabaseConfig} if we have one.
how can i delete all tables with this library without using other solution about that?