jOOQ - support for UPDATE … SET … query with arbitrary degree

穿精又带淫゛_ 提交于 2019-12-13 01:54:25

问题


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() {
    ...
}

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

It is possible to insert into a table:

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

It is not possible to update a table:

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

Could this functionality be added to jOOQ 3.7?

Which workaround can we use for now?


回答1:


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())

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



来源:https://stackoverflow.com/questions/32251307/update-more-than-22-values-in-jooq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!