jOOQ-支持UPDATE ... SET ...任意程度的查询 [英] jOOQ - support for UPDATE ... SET ... query with arbitrary degree
问题描述
我有两个功能:一个返回字段列表,另一个返回选择查询(用于选择字段的相应值).
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?
推荐答案
妙招, RowN
作为第一个参数,该类型从 https://github.com/jOOQ/jOOQ/issues/4475
Nice catch, there's a missing method on the UpdateSetFirstStep
DSL API, which accepts RowN
as a first argument, the type returned from DSL.row(Collection)
. This should be fixed for 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屋!