从JOOQ解析器结果获取表/列元数据 [英] Get table/column metadata from JOOQ parser result
问题描述
使用JOOQ解析器API,我可以解析以下查询,并从生成的Query对象获取参数映射.由此,我可以知道有一个参数,它的名称是"something".
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".
但是,我一直无法弄清楚如何确定参数"something"是否已分配给名为"BAZ"的列,并且该列是表"BAR"的一部分.
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".
解析器API是否可以获取与每个参数关联的表/列元数据?
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();
推荐答案
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.
但是,有很多手动管道需要完成.例如,VisitListener
仅将A.BAZ
作为列引用,而没有直接知道A
是重命名的表BAR
.当您访问BAR A
表达式时,您将必须跟踪自己的重命名.
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.
这篇关于从JOOQ解析器结果获取表/列元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!