SQLException: database in auto-commit mode
See original GitHub issueHi. I use SqlDelight on JVM. A small http backend with a single database connection. When I do almost simultaneous queries I get a weird error.
With 1.3.0 and sqlite jdbc 3.27.2.1 it was: [SQLITE_ERROR] SQL error or missing database (cannot start a transaction within a transaction)
.
I decided to update SqlDelight and now with 1.4.0 and 3.32.3 (latest releases) I have java.sql.SQLException: database in auto-commit mode
. I’m not sure, but seems I’m getting an issue somehow connected with 1706.
It’t not 100% reproducible, 1 time of 3-5 queries.
My guess according to the code that after the first transaction JdbcDriver.kt changes autoCommit
value to true
and then second query can’t finish it normally.
To be more precise:
- t1 enclosing transaction started
- t2 enclosing transaction started
- t1 commited and JdbcDriver.kt set
connection.autoCommit = true
in endTransaction method - t2 commited and
SQLiteConnection.java
from sqlite-jdbc throws exception as it’s in autoCommit state:
@Override
public void commit() throws SQLException {
checkOpen();
if (connectionConfig.isAutoCommit())
throw new SQLException("database in auto-commit mode");
db.exec("commit;", getAutoCommit());
db.exec(connectionConfig.transactionPrefix(), getAutoCommit());
}
Am I wrong that don’t synchronize my queries? I thought database will handle it.
That’s my code
var response: Response? = null
dbHelper.database.transaction {
response = findSchedulesInternal(userId, uuid, scheduleId) // several select queries inside
}
That’s what I get:
java.sql.SQLException: database in auto-commit mode
at org.sqlite.SQLiteConnection.commit(SQLiteConnection.java:403)
at com.squareup.sqldelight.sqlite.driver.JdbcDriver$Transaction.endTransaction(JdbcDriver.kt:96)
at com.squareup.sqldelight.Transacter$Transaction.endTransaction$runtime(Transacter.kt:113)
at com.squareup.sqldelight.TransacterImpl.transactionWithWrapper(Transacter.kt:223)
at com.squareup.sqldelight.TransacterImpl.transaction(Transacter.kt:197)
at com.squareup.sqldelight.Transacter$DefaultImpls.transaction$default(Transacter.kt:82)
at com.eventsheep.sdk.event.service.dashboard.scheduleItem.FindScheduleItemService.findByScheduleId-NF5XIXo(FindScheduleItemService.kt:33)
…
Issue Analytics
- State:
- Created 3 years ago
- Comments:7
Top GitHub Comments
Hi, @AlecStrong.
According to this issue it seems nobody uses SqlDelight within JVM except me) I’d like to use it in the production, but this bug ruins everything. I tried to look into the code, but it’s not so obvious without some expertise.
Could you look into the issue again?
thank you! I will take a look