Get table/column metadata from JOOQ parser result

最后都变了- 提交于 2019-12-02 04:22:26

问题


Using the JOOQ parser API, I'm able to parse the following query and get the parameters map from the resulting Query object. From this, I can tell that there is one parameter, and it's name is "something".

However, I haven't been able to figure out how to determine that the parameter "something" is assigned to a column named "BAZ" and that column is part of the table "BAR".

Does the parser API have a way to get the table/column metadata associated to each parameter?

String sql = "SELECT A.FOO FROM BAR A WHERE A.BAZ = :something";

DSLContext context = DSL.using...
Parser parser = context.parser();
Query query = parser.parseQuery(sql);


Map<String, Param<?>> params = query.getParams();

回答1:


As of jOOQ 3.11, the SPI that can be used to access the internal expression tree is the VisitListener SPI, which you have to attach to your context.configuration() prior to parsing. It will then be invoked whenever you traverse that expression tree, e.g. on your query.getParams() call.

However, there's quite a bit of manual plumbing that needs to be done. For example, the VisitListener will only see A.BAZ as a column reference without knowing directly that A is the renamed table BAR. You will have to keep track of such renaming yourself when you visit the BAR A expression.



来源:https://stackoverflow.com/questions/53696181/get-table-column-metadata-from-jooq-parser-result

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