agrosner / DBFlow

A blazing fast, powerful, and very simple ORM android database library that writes database code for you.
MIT License
4.87k stars 598 forks source link

IllegalStateException: Cannot perform this operation because there is no current transaction #1719

Open royorange opened 3 years ago

royorange commented 3 years ago

DBFlow Version: 4.2.4

Bug or Feature Request: Runtime exception

Description: The lib works well, but I found some crash issue from users after a migration. The online log collected the exception, here is the stacktrace:

Caused by: java.lang.IllegalStateException: Cannot perform this operation because there is no current transaction.
    at android.database.sqlite.SQLiteSession.throwIfNoTransaction(SQLiteSession.java:937)
    at android.database.sqlite.SQLiteSession.endTransaction(SQLiteSession.java:410)
    at android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:611)
    at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:442)
    at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:332)
    at com.raizlabs.android.dbflow.structure.database.FlowSQLiteOpenHelper.getDatabase(FlowSQLiteOpenHelper.java:62)
    at com.raizlabs.android.dbflow.config.DatabaseDefinition.getWritableDatabase(DatabaseDefinition.java:257)
    at com.raizlabs.android.dbflow.sql.queriable.ModelLoader.load(ModelLoader.java:36)
    at com.raizlabs.android.dbflow.sql.queriable.ListModelLoader.load(ListModelLoader.java:25)
    at com.raizlabs.android.dbflow.sql.language.BaseModelQueriable.queryList(BaseModelQueriable.java:61)
    at com.raizlabs.android.dbflow.sql.language.Where.queryList(Where.java:236)

The migration is about change the primary key of one table, and everything works well during the test. the migration sql file is:

drop table SearchData;
create table SearchData
(
  text              TEXT,
  url               TEXT,
  updateDate        INTEGER,
  primary key(text)
);
COMMIT;

How can I fix it? Thanks

royorange commented 3 years ago

It looks like something wrong in the FlowSQLiteOpenHelper.onUpgrade method?