https://kotlinlang.org logo
Title
k

Kevin Janvier Chinabalire

08/23/2018, 7:30 AM
@Kulwinder Singh i implemented that but getting
java.lang.IllegalStateException: Cannot perform this operation because there is no current transaction.
It run for the first time then crash for second time
fun clearAndResetAllTables(): Boolean {
        if (db== null) return false

        // reset all auto-incrementalValues
        val query = SimpleSQLiteQuery("DELETE FROM sqlite_sequence")

        db!!.beginTransaction()
        return try {
            db!!.clearAllTables()
            db!!.query(query)
            db!!.setTransactionSuccessful()
            true
        } catch (e: Exception){
            false
        } finally {
            db!!.endTransaction()
        }
    }
:stackoverflow: 1
g

gildor

08/23/2018, 7:48 AM
Terrible code style, do not copy this in your project. all those
!!
☝️ 1
In general code looks correct, check that you call beginTransaction all the time before endTransaction
d

Denis A

08/23/2018, 7:53 AM
replace first string to val db = db ?: return
g

gildor

08/23/2018, 7:53 AM
yes, exactly.
I will propose change original SO comment to avoid all
those !!
k

Kevin Janvier Chinabalire

08/23/2018, 8:16 AM
I do end the transaction …. but am getting this
Cannot perform this operation because there is no current transaction.
I get a crash on finally block …
it has worked .. i add a check inside finally
g

gildor

08/23/2018, 8:31 AM
I do end the transaction
This error about begin transaction, not about end transaction Check that you begin transaction in all cases and that you don’t call this method concurrently