Feat(jdbc): Implement setObject(int, Object) in JDBC4PreparedStatement

This commit is contained in:
Orange flavored banana
2025-10-30 09:54:42 +09:00
parent 79442b3da6
commit 53ab453015

View File

@@ -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 {