[jOOQ/jOOQ#14067] ClobBinding and BlobBinding shouldn't bind a null value on PreparedStatement::setClob and ::setBlob

This commit is contained in:
Lukas Eder 2022-10-11 13:03:45 +02:00
parent c48dd42de3
commit eacceadee4
2 changed files with 21 additions and 4 deletions

View File

@ -37,11 +37,13 @@
*/
package org.jooq.impl;
import static org.jooq.SQLDialect.FIREBIRD;
import static org.jooq.impl.DefaultExecuteContext.localConnection;
import static org.jooq.impl.DefaultExecuteContext.localTargetConnection;
import static org.jooq.impl.Tools.asInt;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;
@ -97,10 +99,18 @@ public class BlobBinding implements Binding<byte[], byte[]> {
public final void set(BindingSetStatementContext<byte[]> ctx) throws SQLException {
// [#12964] We don't support the whole Blob API for R2DBC yet.
if (ctx.statement() instanceof R2DBCPreparedStatement)
if (ctx.statement() instanceof R2DBCPreparedStatement) {
ctx.statement().setBytes(ctx.index(), ctx.value());
else
ctx.statement().setBlob(ctx.index(), newBlob(ctx, ctx.value(), ctx.statement().getConnection()));
}
else {
Blob blob = newBlob(ctx, ctx.value(), ctx.statement().getConnection());
// [#14067] Workaround for Firebird bug https://github.com/FirebirdSQL/jaybird/issues/712
if (blob == null && ctx.family() == FIREBIRD)
ctx.statement().setNull(ctx.index(), Types.BLOB);
else
ctx.statement().setBlob(ctx.index(), blob);
}
}
@Override

View File

@ -37,6 +37,7 @@
*/
package org.jooq.impl;
import static org.jooq.SQLDialect.FIREBIRD;
import static org.jooq.impl.DefaultExecuteContext.localConnection;
import static org.jooq.impl.DefaultExecuteContext.localTargetConnection;
import static org.jooq.impl.Tools.asInt;
@ -95,7 +96,13 @@ public class ClobBinding implements Binding<String, String> {
@Override
public final void set(BindingSetStatementContext<String> ctx) throws SQLException {
ctx.statement().setClob(ctx.index(), newClob(ctx, ctx.value()));
Clob clob = newClob(ctx, ctx.value());
// [#14067] Workaround for Firebird bug https://github.com/FirebirdSQL/jaybird/issues/712
if (clob == null && ctx.family() == FIREBIRD)
ctx.statement().setNull(ctx.index(), Types.CLOB);
else
ctx.statement().setClob(ctx.index(), clob);
}
@Override