<@U5FHN1J7L> i implemented that but getting `java....
# android
k
@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
Copy code
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
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
replace first string to val db = db ?: return
g
yes, exactly.
I will propose change original SO comment to avoid all
those !!
k
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
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