[jOOQ/jOOQ#17850] Error when reading NULL bind value of type NVARCHAR from MySQL driver

This commit is contained in:
Lukas Eder 2025-01-09 16:01:37 +01:00
parent a379de090d
commit 9c825bbd77

View File

@ -79,6 +79,7 @@ import static org.jooq.SQLDialect.HSQLDB;
import static org.jooq.SQLDialect.MYSQL;
// ...
// ...
// ...
import static org.jooq.SQLDialect.POSTGRES;
// ...
// ...
@ -5102,6 +5103,13 @@ public class DefaultBinding<T, U> implements Binding<T, U> {
final String get0(BindingGetResultSetContext<U> ctx) throws SQLException {
if (NO_SUPPORT_NVARCHAR.contains(ctx.dialect()))
return fallback.get0(ctx);
// [#17850] In some cases, NULL values can't be read as NVARCHAR as the
// MySQL driver will throw an exception due to a wrong encoding (e.g. ISO 8859-1)
else if (ctx.family() == MYSQL)
return ctx.resultSet().getObject(ctx.index()) == null
? null
: autoRtrim(ctx, dataType, ctx.resultSet().getNString(ctx.index()));
else
return autoRtrim(ctx, dataType, ctx.resultSet().getNString(ctx.index()));
}