I am having a problem completing a SQLite transaction and am completely puzzled by how to do this. This is completely similar to this error since 2007.
I create an employee table (which refers to another entity table) as follows (edited for brevity):
CREATE TABLE employee (_id INTEGER NOT NULL, PRIMARY KEY ( _id ) , FOREIGN KEY (_id) REFERENCES entity(_id) ON DELETE cascade ON UPDATE cascade DEFERRABLE INITIALLY DEFERRED )
Then I start the transaction as follows (using the SQLiteDatabase object, I also report the status of the transaction in the log):
>> In transaction: false beginTransaction(); >> In transaction: true doSomeWrongINSERT(); setTransactionSuccessful(); endTransaction(); >> In transaction: false SQLiteConstraintException: foreign key constraint failed (code 19)
OK, everything is fine. Now, if I try to start a new transaction or rollback, both fail:
>> In transaction: false beginTransaction(); android.database.sqlite.SQLiteException: cannot start a transaction within a transaction (code 1)
>> In transaction: false endTransaction(); java.lang.IllegalStateException: Cannot perform this operation because there is no current transaction.
Note that all this did not happen if the FKs are immediate rather than delayed.
android sqlite sqlexception
m0skit0
source share