Skip to content

Commit

Permalink
[#5264] PostgreSQL SMALLINT function arguments should always be cast …
Browse files Browse the repository at this point in the history
…explicitly
  • Loading branch information
lukaseder committed Jul 4, 2016
1 parent e91da53 commit 4137056
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions jOOQ/src/main/java/org/jooq/impl/AbstractRoutine.java
Expand Up @@ -41,6 +41,7 @@
package org.jooq.impl;

import static java.lang.Boolean.TRUE;
import static java.util.Arrays.asList;
import static org.jooq.Clause.FIELD;
import static org.jooq.Clause.FIELD_FUNCTION;
import static org.jooq.SQLDialect.FIREBIRD;
Expand Down Expand Up @@ -881,6 +882,12 @@ protected final boolean isOverloaded() {
return overloaded;
}

private final boolean pgArgNeedsCasting(Parameter<?> parameter) {
// [#5264] Overloaded methods always need casting for overload resolution
// Some data types also need casting because expressions are automatically promoted to a "higher" type
return isOverloaded() || asList(Byte.class, Short.class).contains(parameter.getType());
}




Expand Down Expand Up @@ -1152,6 +1159,7 @@ private class RoutineField extends AbstractField<T> {
: AbstractRoutine.this.type);
}

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void accept(Context<?> ctx) {
RenderContext local = create(ctx).renderContext();
Expand All @@ -1165,22 +1173,19 @@ public void accept(Context<?> ctx) {
continue;

// Disambiguate overloaded function signatures
if (ctx.family() == POSTGRES) {
if (ctx.family() == POSTGRES)

// [#4920] In case there are any unnamed parameters, we mustn't
if (hasUnnamedParameters()) {
if (isOverloaded())
fields.add(getInValues().get(parameter).cast(parameter.getType()));
if (hasUnnamedParameters())
if (pgArgNeedsCasting(parameter))
fields.add(new Cast(getInValues().get(parameter), parameter.getDataType()));
else
fields.add(getInValues().get(parameter));
}
else {
if (isOverloaded())
fields.add(field("{0} := {1}", name(parameter.getName()), getInValues().get(parameter).cast(parameter.getType())));
else
if (pgArgNeedsCasting(parameter))
fields.add(field("{0} := {1}", name(parameter.getName()), new Cast(getInValues().get(parameter), parameter.getDataType())));
else
fields.add(field("{0} := {1}", name(parameter.getName()), getInValues().get(parameter)));
}
}
else
fields.add(getInValues().get(parameter));
}
Expand All @@ -1189,9 +1194,8 @@ public void accept(Context<?> ctx) {


// [#3592] Decrease SQL -> PL/SQL context switches with Oracle Scalar Subquery Caching
if (TRUE.equals(settings(ctx.configuration()).isRenderScalarSubqueriesForStoredFunctions())) {
if (TRUE.equals(settings(ctx.configuration()).isRenderScalarSubqueriesForStoredFunctions()))
result = DSL.select(result).asField();
}

ctx.visit(result);
}
Expand Down

0 comments on commit 4137056

Please sign in to comment.