Skip to content

Commit

Permalink
Close temporary PreparedStatement in Sqlite JDBC Driver (#4589)
Browse files Browse the repository at this point in the history
The type is AutoCloseable and we should close it. Failing to do so leaks the PreparedStatement.
  • Loading branch information
MariusVolkhart authored Sep 9, 2023
1 parent 59f48be commit 90d139b
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import app.cash.sqldelight.driver.jdbc.JdbcDriver
import app.cash.sqldelight.driver.jdbc.sqlite.JdbcSqliteDriver.Companion.IN_MEMORY
import java.sql.Connection
import java.sql.DriverManager
import java.sql.PreparedStatement
import java.util.Properties
import kotlin.concurrent.getOrSet

Expand Down Expand Up @@ -57,15 +58,15 @@ private fun connectionManager(url: String, properties: Properties) = when (url)

private abstract class JdbcSqliteDriverConnectionManager : ConnectionManager {
override fun Connection.beginTransaction() {
prepareStatement("BEGIN TRANSACTION").execute()
prepareStatement("BEGIN TRANSACTION").use(PreparedStatement::execute)
}

override fun Connection.endTransaction() {
prepareStatement("END TRANSACTION").execute()
prepareStatement("END TRANSACTION").use(PreparedStatement::execute)
}

override fun Connection.rollbackTransaction() {
prepareStatement("ROLLBACK TRANSACTION").execute()
prepareStatement("ROLLBACK TRANSACTION").use(PreparedStatement::execute)
}
}

Expand Down

0 comments on commit 90d139b

Please sign in to comment.