From 53ab45301515e94379f3da35e472339e8706e90c Mon Sep 17 00:00:00 2001 From: Orange flavored banana <106858113+moonwhistle@users.noreply.github.com> Date: Thu, 30 Oct 2025 09:54:42 +0900 Subject: [PATCH] Feat(jdbc): Implement setObject(int, Object) in JDBC4PreparedStatement --- .../turso/jdbc4/JDBC4PreparedStatement.java | 49 +++++++++++++++++-- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/bindings/java/src/main/java/tech/turso/jdbc4/JDBC4PreparedStatement.java b/bindings/java/src/main/java/tech/turso/jdbc4/JDBC4PreparedStatement.java index 6eba787b5..72c78e5e8 100644 --- a/bindings/java/src/main/java/tech/turso/jdbc4/JDBC4PreparedStatement.java +++ b/bindings/java/src/main/java/tech/turso/jdbc4/JDBC4PreparedStatement.java @@ -26,7 +26,9 @@ import java.util.Calendar; import tech.turso.annotations.SkipNullableCheck; import tech.turso.core.TursoResultSet; -/** JDBC 4 PreparedStatement implementation for Turso databases. */ +/** + * JDBC 4 PreparedStatement implementation for Turso databases. + */ public final class JDBC4PreparedStatement extends JDBC4Statement implements PreparedStatement { private final String sql; @@ -36,7 +38,7 @@ public final class JDBC4PreparedStatement extends JDBC4Statement implements Prep * Creates a new JDBC4PreparedStatement. * * @param connection the database connection - * @param sql the SQL statement to prepare + * @param sql the SQL statement to prepare * @throws SQLException if a database access error occurs */ public JDBC4PreparedStatement(JDBC4Connection connection, String sql) throws SQLException { @@ -189,7 +191,45 @@ public final class JDBC4PreparedStatement extends JDBC4Statement implements Prep @Override public void setObject(int parameterIndex, Object x) throws SQLException { - // TODO + requireNonNull(this.statement); + if (x == null) { + this.statement.bindNull(parameterIndex); + return; + } + if (x instanceof String) { + setString(parameterIndex, (String) x); + } else if (x instanceof Integer) { + setInt(parameterIndex, (Integer) x); + } else if (x instanceof Long) { + setLong(parameterIndex, (Long) x); + } else if (x instanceof Boolean) { + setBoolean(parameterIndex, (Boolean) x); + } else if (x instanceof Double) { + setDouble(parameterIndex, (Double) x); + } else if (x instanceof Float) { + setFloat(parameterIndex, (Float) x); + } else if (x instanceof Byte) { + setByte(parameterIndex, (Byte) x); + } else if (x instanceof Short) { + setShort(parameterIndex, (Short) x); + } else if (x instanceof byte[]) { + setBytes(parameterIndex, (byte[]) x); + } else if (x instanceof java.sql.Timestamp) { + setTimestamp(parameterIndex, (java.sql.Timestamp) x); + } else if (x instanceof java.sql.Date) { + setDate(parameterIndex, (java.sql.Date) x); + } else if (x instanceof java.sql.Time) { + setTime(parameterIndex, (java.sql.Time) x); + } else if (x instanceof java.math.BigDecimal) { + setBigDecimal(parameterIndex, (java.math.BigDecimal) x); + } else if (x instanceof Blob || x instanceof Clob || x instanceof InputStream || x instanceof Reader) { + throw new SQLException( + "setObject does not yet support LOB or Stream types because the corresponding set methods are unimplemented. Type found: " + + x.getClass().getName() + ); + } else { + throw new SQLException("Unsupported object type in setObject: " + x.getClass().getName()); + } } @Override @@ -211,7 +251,8 @@ public final class JDBC4PreparedStatement extends JDBC4Statement implements Prep @Override public void setCharacterStream(int parameterIndex, Reader reader, int length) - throws SQLException {} + throws SQLException { + } @Override public void setRef(int parameterIndex, Ref x) throws SQLException {