From 1490028bd2d2e5da58dc4245edd23825a8acf483 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Tue, 19 Mar 2024 16:20:33 +0100 Subject: [PATCH] [jOOQ/jOOQ#16483] Add Settings.renderNullifEmptyStringForBindValues to emulate Oracle behaviour on other RDBMS --- .../src/main/java/org/jooq/conf/Settings.java | 52 +++++++++++++++++++ jOOQ/src/main/java/org/jooq/impl/Val.java | 27 +++++++++- .../org/jooq/xsd/jooq-runtime-3.20.0.xsd | 6 +++ 3 files changed, 83 insertions(+), 2 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/conf/Settings.java b/jOOQ/src/main/java/org/jooq/conf/Settings.java index 4eed197f70..09419241fa 100644 --- a/jOOQ/src/main/java/org/jooq/conf/Settings.java +++ b/jOOQ/src/main/java/org/jooq/conf/Settings.java @@ -70,6 +70,8 @@ public class Settings @XmlElement(defaultValue = "false") protected Boolean renderFormatted = false; protected RenderFormatting renderFormatting; + @XmlElement(defaultValue = "false") + protected Boolean renderNullifEmptyStringForBindValues = false; @XmlElement(defaultValue = "NEVER") @XmlSchemaType(name = "string") protected AutoAliasExpressions renderAutoAliasedDerivedTableExpressions = AutoAliasExpressions.NEVER; @@ -897,6 +899,34 @@ public class Settings this.renderFormatting = value; } + /** + * Whether to wrap String typed bind values with NULLIF(?, '') for Oracle compatibility. + *

+ * This feature is available in the commercial distribution only. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isRenderNullifEmptyStringForBindValues() { + return renderNullifEmptyStringForBindValues; + } + + /** + * Whether to wrap String typed bind values with NULLIF(?, '') for Oracle compatibility. + *

+ * This feature is available in the commercial distribution only. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setRenderNullifEmptyStringForBindValues(Boolean value) { + this.renderNullifEmptyStringForBindValues = value; + } + /** * Whether to auto-alias expressions in derived tables. *

@@ -6840,6 +6870,17 @@ public class Settings return this; } + /** + * Whether to wrap String typed bind values with NULLIF(?, '') for Oracle compatibility. + *

+ * This feature is available in the commercial distribution only. + * + */ + public Settings withRenderNullifEmptyStringForBindValues(Boolean value) { + setRenderNullifEmptyStringForBindValues(value); + return this; + } + /** * Whether to auto-alias expressions in derived tables. *

@@ -9455,6 +9496,7 @@ public class Settings builder.append("renderLocale", renderLocale); builder.append("renderFormatted", renderFormatted); builder.append("renderFormatting", renderFormatting); + builder.append("renderNullifEmptyStringForBindValues", renderNullifEmptyStringForBindValues); builder.append("renderAutoAliasedDerivedTableExpressions", renderAutoAliasedDerivedTableExpressions); builder.append("renderOptionalAssociativityParentheses", renderOptionalAssociativityParentheses); builder.append("renderOptionalAsKeywordForTableAliases", renderOptionalAsKeywordForTableAliases); @@ -9813,6 +9855,15 @@ public class Settings return false; } } + if (renderNullifEmptyStringForBindValues == null) { + if (other.renderNullifEmptyStringForBindValues!= null) { + return false; + } + } else { + if (!renderNullifEmptyStringForBindValues.equals(other.renderNullifEmptyStringForBindValues)) { + return false; + } + } if (renderAutoAliasedDerivedTableExpressions == null) { if (other.renderAutoAliasedDerivedTableExpressions!= null) { return false; @@ -11733,6 +11784,7 @@ public class Settings result = ((prime*result)+((renderLocale == null)? 0 :renderLocale.hashCode())); result = ((prime*result)+((renderFormatted == null)? 0 :renderFormatted.hashCode())); result = ((prime*result)+((renderFormatting == null)? 0 :renderFormatting.hashCode())); + result = ((prime*result)+((renderNullifEmptyStringForBindValues == null)? 0 :renderNullifEmptyStringForBindValues.hashCode())); result = ((prime*result)+((renderAutoAliasedDerivedTableExpressions == null)? 0 :renderAutoAliasedDerivedTableExpressions.hashCode())); result = ((prime*result)+((renderOptionalAssociativityParentheses == null)? 0 :renderOptionalAssociativityParentheses.hashCode())); result = ((prime*result)+((renderOptionalAsKeywordForTableAliases == null)? 0 :renderOptionalAsKeywordForTableAliases.hashCode())); diff --git a/jOOQ/src/main/java/org/jooq/impl/Val.java b/jOOQ/src/main/java/org/jooq/impl/Val.java index 927bf6a021..a406e380b0 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Val.java +++ b/jOOQ/src/main/java/org/jooq/impl/Val.java @@ -37,6 +37,7 @@ */ package org.jooq.impl; +import static java.lang.Boolean.TRUE; import static java.util.stream.Collectors.joining; // ... import static org.jooq.conf.ParamType.INLINED; @@ -44,7 +45,9 @@ import static org.jooq.conf.ParamType.NAMED; import static org.jooq.conf.ParamType.NAMED_OR_INLINED; import static org.jooq.impl.AbstractRowAsField.acceptMultisetContent; import static org.jooq.impl.AbstractRowAsField.forceMultisetContent; +import static org.jooq.impl.DSL.inline; import static org.jooq.impl.DSL.sql; +import static org.jooq.impl.Names.N_NULLIF; import static org.jooq.impl.QueryPartListView.wrap; import static org.jooq.impl.SQLDataType.OTHER; import static org.jooq.impl.SQLDataType.VARCHAR; @@ -215,7 +218,23 @@ final class Val extends AbstractParam implements UEmpty { try { - getBinding().sql(new DefaultBindingSQLContext<>(ctx.configuration(), ctx.data(), r, value, getBindVariable(ctx))); + + + + + + + + + + + + + + + + + accept0(r); } catch (SQLException e) { throw new DataAccessException("Error while generating SQL for Binding", e); @@ -232,7 +251,11 @@ final class Val extends AbstractParam implements UEmpty { } } - private void acceptDefaultEmbeddable(Context ctx) { + private final void accept0(RenderContext ctx) throws SQLException { + getBinding().sql(new DefaultBindingSQLContext<>(ctx.configuration(), ctx.data(), ctx, value, getBindVariable(ctx))); + } + + private final void acceptDefaultEmbeddable(Context ctx) { ctx.data(DATA_LIST_ALREADY_INDENTED, true, c -> c.visit(wrap(embeddedFields(this)))); } diff --git a/jOOQ/src/main/resources/org/jooq/xsd/jooq-runtime-3.20.0.xsd b/jOOQ/src/main/resources/org/jooq/xsd/jooq-runtime-3.20.0.xsd index addd321fd1..1d858d2afa 100644 --- a/jOOQ/src/main/resources/org/jooq/xsd/jooq-runtime-3.20.0.xsd +++ b/jOOQ/src/main/resources/org/jooq/xsd/jooq-runtime-3.20.0.xsd @@ -130,6 +130,12 @@ providing a name to parameters, resulting in :1 or @1 + + +This feature is available in the commercial distribution only.]]> + +