[#1735] Add Setting to indicate that bind values should not be cast
This commit is contained in:
parent
ccefb254ad
commit
de3a75127c
@ -62,6 +62,7 @@ import org.jooq.Table;
|
||||
import org.jooq.VisitContext;
|
||||
import org.jooq.VisitListener;
|
||||
import org.jooq.VisitListenerProvider;
|
||||
import org.jooq.conf.ParamCastMode;
|
||||
import org.jooq.conf.ParamType;
|
||||
import org.jooq.conf.Settings;
|
||||
import org.jooq.conf.SettingsTools;
|
||||
@ -93,10 +94,11 @@ abstract class AbstractContext<C extends Context<C>> extends AbstractScope imple
|
||||
|
||||
// [#2694] Unified RenderContext and BindContext traversal
|
||||
final ParamType forcedParamType;
|
||||
final boolean castModeOverride;
|
||||
CastMode castMode;
|
||||
ParamType paramType = ParamType.INDEXED;
|
||||
boolean qualifySchema = true;
|
||||
boolean qualifyCatalog = true;
|
||||
CastMode castMode = CastMode.DEFAULT;
|
||||
|
||||
AbstractContext(Configuration configuration, PreparedStatement stmt) {
|
||||
super(configuration);
|
||||
@ -133,9 +135,19 @@ abstract class AbstractContext<C extends Context<C>> extends AbstractScope imple
|
||||
this.visitClauses = null;
|
||||
}
|
||||
|
||||
forcedParamType = SettingsTools.getStatementType(settings()) == StatementType.STATIC_STATEMENT
|
||||
this.forcedParamType = SettingsTools.getStatementType(settings()) == StatementType.STATIC_STATEMENT
|
||||
? ParamType.INLINED
|
||||
: null;
|
||||
|
||||
ParamCastMode m = settings().getParamCastMode();
|
||||
this.castModeOverride =
|
||||
m != ParamCastMode.DEFAULT && m != null;
|
||||
this.castMode =
|
||||
m == ParamCastMode.ALWAYS
|
||||
? CastMode.ALWAYS
|
||||
: m == ParamCastMode.NEVER
|
||||
? CastMode.NEVER
|
||||
: CastMode.DEFAULT;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@ -383,7 +395,7 @@ abstract class AbstractContext<C extends Context<C>> extends AbstractScope imple
|
||||
declareCTE(true);
|
||||
}
|
||||
|
||||
else if (castMode() != CastMode.DEFAULT && !internal.generatesCast()) {
|
||||
else if (!castModeOverride && castMode() != CastMode.DEFAULT && !internal.generatesCast()) {
|
||||
CastMode previous = castMode();
|
||||
|
||||
castMode(CastMode.DEFAULT);
|
||||
@ -593,6 +605,9 @@ abstract class AbstractContext<C extends Context<C>> extends AbstractScope imple
|
||||
sb.append( "bind index [");
|
||||
sb.append(index);
|
||||
sb.append("]");
|
||||
sb.append("\ncast mode [");
|
||||
sb.append(castMode);
|
||||
sb.append("]");
|
||||
sb.append("\ndeclaring [");
|
||||
|
||||
if (declareFields) {
|
||||
|
||||
@ -57,6 +57,9 @@
|
||||
-->
|
||||
<element name="paramType" type="jooq-runtime:ParamType" minOccurs="0" maxOccurs="1" default="INDEXED"/>
|
||||
|
||||
<!-- Whether rendered bind values should be cast to their respective type. -->
|
||||
<element name="paramCastMode" type="jooq-runtime:ParamCastMode" minOccurs="0" maxOccurs="1" default="DEFAULT"/>
|
||||
|
||||
<!-- The type of statement that is to be executed -->
|
||||
<element name="statementType" type="jooq-runtime:StatementType" minOccurs="0" maxOccurs="1" default="PREPARED_STATEMENT"/>
|
||||
|
||||
@ -208,6 +211,25 @@
|
||||
</restriction>
|
||||
</simpleType>
|
||||
|
||||
<simpleType name="ParamCastMode">
|
||||
<restriction base="string">
|
||||
|
||||
<!-- Bind values are always cast to their respective type. -->
|
||||
<enumeration value="ALWAYS"/>
|
||||
|
||||
<!-- Bind values are cast to their respective type when needed.
|
||||
|
||||
Some databases are not able to delay bind value type inference until the execution of a statement.
|
||||
They will either reject the value of unknown type, or assume a possibly inappropriate type. In these
|
||||
cases, jOOQ will generate an explicit cast(? as datatype) expression around the bind value to help
|
||||
the query parser do its job. The exact behaviour of this mode is undefined and subject to change. -->
|
||||
<enumeration value="DEFAULT"/>
|
||||
|
||||
<!-- Bind values are never cast to their respective type. -->
|
||||
<enumeration value="NEVER"/>
|
||||
</restriction>
|
||||
</simpleType>
|
||||
|
||||
<simpleType name="StatementType">
|
||||
<restriction base="string">
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user