Skip to content

Conversation

exoego
Copy link

@exoego exoego commented Nov 28, 2023

Problem

I am using Kotlin's SQL Framework https://github.com/JetBrains/Exposed with sqlite-jdbc.

import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.transactions.transaction
(snip)

val sqLiteConfig = SQLiteConfig()
val ds = SQLiteDataSource(sqLiteConfig)
val database = Database.connect(ds)

import org.jetbrains.exposed.sql.transactions.transaction
import org.sqlite.SQLiteErrorCode
import org.sqlite.SQLiteException
import java.time.temporal.Temporal

transaction(db) {
  connection.autoCommit = false
  // do something with DB
}

I want to disable auto-commit for better performance, but it appears that it is not configurable via SQLiteConfig nor SQLiteDataSource.
SQLiteConnectionConfig offers setAutoCommit, but SQLiteConfig#defaultConnectionConfig always use autoCommit = true.

private boolean autoCommit = true;

One can specify connection.autoCommit = false in transaction { ... } DSL, but it is error-prone because one might forget.

Proposal

This PR adds "fake" pragma jdbc.auto_commit, so auto-commit can be configurable via SQLiteConfig.

val prop = new Properties()
prop.setProperty(SQLiteConfig.Pragma.JDBC_AUTO_COMMIT.pragmaName, "true")
val sqLiteConfig = SQLiteConfig(prop)
val ds = SQLiteDataSource(sqLiteConfig)
val database = Database.connect(ds)

@gotson
Copy link
Collaborator

gotson commented Nov 28, 2023

It seems JDBC expects the default to always be true, according to https://stackoverflow.com/a/11022406

It would probably make sense for the exposed framework to allow for such option so that new connections are always set to false.

@exoego
Copy link
Author

exoego commented Nov 28, 2023

I agree autoCommit = true should be the default.
This PR does not change that.
It just allows users to configure autoCommit so they can use this driver for any framework in autoCommit = false mode.

Several JDBC libs offer a configuration point of autoCommit:

@exoego
Copy link
Author

exoego commented Dec 21, 2023

Please take a look.

@exoego exoego closed this by deleting the head repository Aug 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants