Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commons-sql: fix compatibility with 'xerial sqlite driver'
Browse files Browse the repository at this point in the history
SfenKer committed Aug 15, 2024
1 parent 02f6f00 commit 56dc273
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -85,7 +85,30 @@ public void prepare(

this.elements.forEach((position, object) -> {
try {
preparedStatement.setObject(position, object.object(), object.type());
switch (object.type()) {

case VARCHAR, LONGVARCHAR, NVARCHAR, LONGNVARCHAR ->
preparedStatement.setString(position, (String) object.object());

case DOUBLE ->
preparedStatement.setDouble(position, (Double) object.object());

case TINYINT, SMALLINT, INTEGER ->
preparedStatement.setInt(position, (Integer) object.object());

case BIGINT ->
preparedStatement.setLong(position, (Long) object.object());

case FLOAT ->
preparedStatement.setFloat(position, (Float) object.object());

case BOOLEAN ->
preparedStatement.setBoolean(position, (Boolean) object.object());

default -> /* Added due to compatibility with some drivers. */
preparedStatement.setObject(position, object.object(), object.type());

}
} catch (@NotNull Exception exception) {
throw new RuntimeException("Unable to prepare statement due to exception.", exception);
}
Original file line number Diff line number Diff line change
@@ -2,10 +2,10 @@

import org.jetbrains.annotations.NotNull;

import java.sql.SQLType;
import java.sql.JDBCType;

record SqlStatementObject(
@NotNull Integer position,
@NotNull SQLType type,
@NotNull JDBCType type,
@NotNull Object object
) {}

0 comments on commit 56dc273

Please sign in to comment.