question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SQLException: database in auto-commit mode

See original GitHub issue

Hi. 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:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
melnikovdvcommented, Nov 5, 2020

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?

1reaction
AlecStrongcommented, Sep 20, 2020

thank you! I will take a look

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reason for java.sql.SQLException "database in auto-commit ...
When running this from a servlet, you have to make sure that the usage of the Connection is synchronized. Multiple requests could set...
Read more >
Error: The connection object is in auto-commit mode - IBM
Auto-commit mode indicates to the database whether to issue an automatic COMMIT operation after every SQL operation.
Read more >
"Could not commit with auto-commit set on" SQLException ...
Auto-commit mode is enabled by default. · The JDBC driver throws a SQLException when a commit or rollback operation is performed on a...
Read more >
A Guide to Auto-Commit in JDBC - Baeldung
Database connections created with the JDBC API have a feature called auto-commit mode. Turning this mode on can help eliminate boilerplate ...
Read more >
Calling commit() and rollback() in autocommit mode (K&B7 ...
I use Oracle JDBC version 11.x, autocommit mode is true by default, ... SQLException - if a database access error occurs, this method...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found