Skip to content

Commit

Permalink
fix: EXPOSED-269 Incompatible with sqlite-jdbc 3.45.0.0
Browse files Browse the repository at this point in the history
sqlite-jdbc 3.45.0.0 [reintroduced improved support for Statement#getGeneratedKeys()](xerial/sqlite-jdbc@f7d49f6), but the implementation is different from the previous implementation and does not work with Exposed. This is a temporary workaround to fix the crash caused by that until we figure out how we're supposed to use sqlite-jdbc 3.45.0.0+ with Exposed.
  • Loading branch information
joc-a committed Mar 25, 2024
1 parent ba8aaf7 commit 38ee832
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 17 deletions.
4 changes: 4 additions & 0 deletions docs/BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Breaking Changes

## 0.49.0

For SQLite database, Exposed now requires bumping the SQLite JDBC driver version to a minimum of 3.45.0.0.

## 0.48.0

* In `nonNullValueToString` for `KotlinInstantColumnType` and `JavaDateColumnType`, the formatted String for MySQL did not match the format received from the metadata
Expand Down
2 changes: 1 addition & 1 deletion exposed-jdbc/api/exposed-jdbc.api
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public final class org/jetbrains/exposed/sql/statements/jdbc/JdbcDatabaseMetadat
}

public final class org/jetbrains/exposed/sql/statements/jdbc/JdbcPreparedStatementImpl : org/jetbrains/exposed/sql/statements/api/PreparedStatementApi {
public fun <init> (Ljava/sql/PreparedStatement;ZZ)V
public fun <init> (Ljava/sql/PreparedStatement;Z)V
public fun addBatch ()V
public fun cancel ()V
public fun closeIfPossible ()V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,11 @@ class JdbcConnectionImpl(override val connection: Connection) : ExposedConnectio
} else {
PreparedStatement.NO_GENERATED_KEYS
}
return JdbcPreparedStatementImpl(
connection.prepareStatement(sql, generated),
returnKeys,
connection.metaData.supportsGetGeneratedKeys()
)
return JdbcPreparedStatementImpl(connection.prepareStatement(sql, generated), returnKeys)
}

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

override fun executeInBatch(sqls: List<String>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,19 @@ import java.sql.Types
* Class representing a precompiled SQL [statement].
*
* The result set generated by executing this statement contains auto-generated keys based on the value of
* [wasGeneratedKeysRequested] and if the JDBC driver implementation [supportsGetGeneratedKeys].
* [wasGeneratedKeysRequested].
*/
class JdbcPreparedStatementImpl(
val statement: PreparedStatement,
val wasGeneratedKeysRequested: Boolean,
private val supportsGetGeneratedKeys: Boolean
val wasGeneratedKeysRequested: Boolean
) : PreparedStatementApi {
override val resultSet: ResultSet?
get() = when {
!wasGeneratedKeysRequested -> statement.resultSet
supportsGetGeneratedKeys -> statement.generatedKeys
currentDialect is SQLiteDialect -> {
statement.connection.prepareStatement("select last_insert_rowid();").executeQuery()
}
else -> statement.resultSet
else -> statement.generatedKeys
}

override var fetchSize: Int?
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mysql80 = "8.0.33"
oracle12 = "12.2.0.1"
postgre = "42.7.3"
postgreNG = "0.8.9"
sqlLite3 = "3.44.1.0"
sqlLite3 = "3.45.2.0"
sqlserver = "9.4.1.jre8"

springFramework = "6.1.5"
Expand Down

0 comments on commit 38ee832

Please sign in to comment.