[jOOQ/jOOQ#19434] Native implementations of STARTS_WITH, ENDS_WITH, and

CONTAINS should cast arguments to String types if they're not strings
This commit is contained in:
Lukas Eder 2025-11-27 15:53:23 +01:00
parent 44ef086581
commit 83f4c8d503
4 changed files with 27 additions and 76 deletions

View File

@ -221,6 +221,10 @@ implements
ctx.visit(DSL.position(Like.requiresStringCast(value), Like.requiresStringCast(content)).gt(inline(0)));
}
private final void acceptContains(Context<?> ctx, Name name) {
ctx.visit(function(name, BOOLEAN, castIfNeeded(value, String.class), castIfNeeded(content, String.class)));
}
// -------------------------------------------------------------------------
// XXX: Query Object Model
// -------------------------------------------------------------------------

View File

@ -92,60 +92,6 @@ implements
// XXX: QueryPart API
// -------------------------------------------------------------------------
@Override
final boolean parenthesised(Context<?> ctx) {
switch (ctx.family()) {
case CUBRID:
case FIREBIRD:
case H2:
case HSQLDB:
case IGNITE:
case MARIADB:
case MYSQL:
case POSTGRES:
case SQLITE:
case TRINO:
case YUGABYTEDB:
return false;
case DERBY:
return false;
case DUCKDB:
return true;
case CLICKHOUSE:
return true;
default:
return true;
}
}
@Override
public final void accept(Context<?> ctx) {
switch (ctx.family()) {
@ -200,16 +146,19 @@ implements
case DUCKDB:
ctx.visit(function(N_SUFFIX, BOOLEAN, string, suffix));
break;
case CLICKHOUSE:
ctx.visit(function(N_endsWith, BOOLEAN, string, suffix));
case DUCKDB: {
acceptEndsWith(ctx, N_SUFFIX);
break;
}
case CLICKHOUSE: {
acceptEndsWith(ctx, N_endsWith);
break;
}
default:
ctx.visit(function(N_ENDS_WITH, BOOLEAN, string, suffix));
acceptEndsWith(ctx, N_ENDS_WITH);
break;
}
}
@ -231,6 +180,10 @@ implements
ctx.visit(DSL.position(Like.requiresStringCast(string), Like.requiresStringCast(suffix)).eq(iadd(isub(Like.requiresStringCast(string).length(), Like.requiresStringCast(suffix).length()), inline(1))));
}
private final void acceptEndsWith(Context<?> ctx, Name name) {
ctx.visit(function(name, BOOLEAN, castIfNeeded(string, String.class), castIfNeeded(suffix, String.class)));
}
// -------------------------------------------------------------------------
// XXX: Query Object Model
// -------------------------------------------------------------------------

View File

@ -134,12 +134,8 @@ implements
case DUCKDB:
case TRINO:
return true;
case CLICKHOUSE:
return true;
return false;
default:
return true;
@ -199,17 +195,14 @@ implements
case DUCKDB:
case TRINO:
ctx.visit(function(N_STARTS_WITH, BOOLEAN, string, prefix));
break;
case CLICKHOUSE:
ctx.visit(function(N_startsWith, BOOLEAN, string, prefix));
case CLICKHOUSE: {
acceptStartsWith(ctx, N_startsWith);
break;
}
default:
ctx.visit(function(N_STARTS_WITH, BOOLEAN, string, prefix));
acceptStartsWith(ctx, N_STARTS_WITH);
break;
}
}
@ -231,6 +224,10 @@ implements
ctx.visit(DSL.position(Like.requiresStringCast(string), Like.requiresStringCast(prefix)).eq(inline(1)));
}
private final void acceptStartsWith(Context<?> ctx, Name name) {
ctx.visit(function(name, BOOLEAN, castIfNeeded(string, String.class), castIfNeeded(prefix, String.class)));
}
// -------------------------------------------------------------------------
// XXX: Query Object Model
// -------------------------------------------------------------------------

View File

@ -107,10 +107,7 @@ implements
{
private static final JooqLogger log = JooqLogger.getLogger(XMLHandler.class);
private static final boolean debug = false;
static final Set<SQLDialect> ENCODE_BINARY_AS_HEX = SQLDialect.supportedBy();
private final DSLContext ctx;
private final Deque<State<R>> states;
private State<R> s;