jOOQ - 支持 UPDATE ... SET ... 任意程度的查询 [英] jOOQ - support for UPDATE ... SET ... query with arbitrary degree

查看:13
本文介绍了jOOQ - 支持 UPDATE ... SET ... 任意程度的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个函数:一个返回一个字段列表,另一个返回一个选择查询(它选择字段的对应值).

I have two functions: one returns a list of fields, the other returns a select query (which selects the corresponding values of the fields).

private List<Field<?>> fields() {
    ....
}

private Select<?> select() {
    ...
}

请注意,度数是在运行时确定的,它取决于用户输入.因此 List<Field<?>>Select<?>.

Note that the degree is determined at runtime, it depends on the user input. Hence List<Field<?>> and Select<?>.

可以插入到表格中:

context.insertInto(table, fields()).select(select()))

无法更新表:

context.update(table).set(DSL.row(fields()), select())

这个功能可以添加到 jOOQ 3.7 吗?

Could this functionality be added to jOOQ 3.7?

我们现在可以使用哪种解决方法?

Which workaround can we use for now?

推荐答案

很好,在 UpdateSetFirstStep DSL API,它接受 RowN 作为第一个参数,从 DSL.row(Collection).这应该为 jOOQ 3.7 修复:https://github.com/jOOQ/jOOQ/issues/4475

作为一种解决方法,如果您可以忍受被黑客入侵的罪恶感,您可以强制转换为原始类型:

As a workaround, and if you can live with the guilt of the hack, you could cast to raw types:

context.update(table).set((Row1) DSL.row(fields()), (Select) select())

你可以将DSL.row(fields())转换成Row1,因为DSL.row(fields())返回的内部实现类型 实现所有 Row[N] 类型.

You can cast DSL.row(fields()) to Row1, because the internal implementation type returned by DSL.row(fields()) implements all Row[N] types.

这篇关于jOOQ - 支持 UPDATE ... SET ... 任意程度的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆