JOOQ中是否实现了setFixedCHAR()
Is setFixedCHAR() implemented in JOOQ
我们的 oracle 数据库无法更改,并且有很多列表示为 CHARS。目前,我在进行比较时手动将参数填充到字段的长度,例如给定 foo 是 db 'foo '
中的 char(5)
String foo = "foo"
...
.where(FOO_TABLE.FOO.equal(StringUtils.rightPad(foo,FOO_TABLE.FOO.getDataType().length()))
有什么方法可以告诉 jooq foo 是一个字符,因此它执行填充比较,例如在生锈的机器人回答中 here
您可以为所有 CHAR
列实施 data type binding 并在生成的 SQL 字符串中转换绑定变量:
@Override
public final void sql(BindingSQLContext<String> ctx) throws SQLException {
ctx.render().sql("CAST(? AS CHAR(5))");
}
(我刚刚注意到无法通过这种方式访问 CHAR
长度...,这应该是固定的:https://github.com/jOOQ/jOOQ/issues/5223)
或者在将绑定变量绑定到准备好的语句之前缩短/填充绑定变量。或者您可以 use that logic you referenced to 直接在数据类型绑定的变量绑定逻辑中。
@Override
public final void set(BindingSetStatementContext<String> ctx) throws SQLException {
ctx.statement()
.unwrap(OraclePreparedStatement.class)
.setFixedChar(ctx.index(), ctx.value());
}
这些方法中的任何一种都只允许您实现此逻辑一次。
我们的 oracle 数据库无法更改,并且有很多列表示为 CHARS。目前,我在进行比较时手动将参数填充到字段的长度,例如给定 foo 是 db 'foo '
中的 char(5) String foo = "foo"
...
.where(FOO_TABLE.FOO.equal(StringUtils.rightPad(foo,FOO_TABLE.FOO.getDataType().length()))
有什么方法可以告诉 jooq foo 是一个字符,因此它执行填充比较,例如在生锈的机器人回答中 here
您可以为所有 CHAR
列实施 data type binding 并在生成的 SQL 字符串中转换绑定变量:
@Override
public final void sql(BindingSQLContext<String> ctx) throws SQLException {
ctx.render().sql("CAST(? AS CHAR(5))");
}
(我刚刚注意到无法通过这种方式访问 CHAR
长度...,这应该是固定的:https://github.com/jOOQ/jOOQ/issues/5223)
或者在将绑定变量绑定到准备好的语句之前缩短/填充绑定变量。或者您可以 use that logic you referenced to 直接在数据类型绑定的变量绑定逻辑中。
@Override
public final void set(BindingSetStatementContext<String> ctx) throws SQLException {
ctx.statement()
.unwrap(OraclePreparedStatement.class)
.setFixedChar(ctx.index(), ctx.value());
}
这些方法中的任何一种都只允许您实现此逻辑一次。