Skip to content

Commit

Permalink
fix: EXPOSED-162 SQLite generatedKeys exception
Browse files Browse the repository at this point in the history
Support for getGeneratedKeys() was dropped in the sqlite jdbc version 3.43.0.0. This caused a SQLFeatureNotSupportedException when using this version with Exposed, so the old implementation of getGeneratedKeys() was used in Exposed to retain the previous behaviour.
  • Loading branch information
joc-a committed Sep 6, 2023
1 parent f3a295a commit ff5a6e9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object Versions {
const val oracle12 = "12.2.0.1"
const val postgre = "42.4.0"
const val postgreNG = "0.8.9"
const val sqlLite3 = "3.36.0.3"
const val sqlLite3 = "3.43.0.0"
const val sqlserver = "9.4.1.jre8"

/** Spring **/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,19 @@ class JdbcConnectionImpl(override val connection: Connection) : ExposedConnectio
} else {
PreparedStatement.NO_GENERATED_KEYS
}
return JdbcPreparedStatementImpl(connection.prepareStatement(sql, generated), returnKeys)
return JdbcPreparedStatementImpl(
connection.prepareStatement(sql, generated),
returnKeys,
connection.metaData.supportsGetGeneratedKeys()
)
}

override fun prepareStatement(sql: String, columns: Array<String>): PreparedStatementApi {
return JdbcPreparedStatementImpl(connection.prepareStatement(sql, columns), true)
return JdbcPreparedStatementImpl(
connection.prepareStatement(sql, columns),
true,
connection.metaData.supportsGetGeneratedKeys()
)
}

override fun executeInBatch(sqls: List<String>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,24 @@ import org.jetbrains.exposed.sql.BinaryColumnType
import org.jetbrains.exposed.sql.BlobColumnType
import org.jetbrains.exposed.sql.IColumnType
import org.jetbrains.exposed.sql.statements.api.PreparedStatementApi
import org.jetbrains.exposed.sql.vendors.SQLiteDialect
import org.jetbrains.exposed.sql.vendors.currentDialect
import java.io.InputStream
import java.sql.PreparedStatement
import java.sql.ResultSet
import java.sql.Types

class JdbcPreparedStatementImpl(val statement: PreparedStatement, val wasGeneratedKeysRequested: Boolean) : PreparedStatementApi {
class JdbcPreparedStatementImpl(val statement: PreparedStatement, val wasGeneratedKeysRequested: Boolean, private val supportsGetGeneratedKeys: Boolean) : PreparedStatementApi {
override val resultSet: ResultSet?
get() = if (wasGeneratedKeysRequested) statement.generatedKeys else statement.resultSet
get() = if (wasGeneratedKeysRequested) {
if (supportsGetGeneratedKeys) {
statement.generatedKeys
} else if (currentDialect is SQLiteDialect) {
statement.connection.prepareStatement("select last_insert_rowid();").executeQuery()
} else {
statement.resultSet
}
} else statement.resultSet

override var fetchSize: Int?
get() = statement.fetchSize
Expand Down

0 comments on commit ff5a6e9

Please sign in to comment.