I need to get the list of columns in a select using the JOOQ SQL parser. In the example below it would return the list with two entries: 'sk' and 'aa'. Debugging the program I can see in the Query.select
field the list of columns, but I cannot find in the Query
class a method to retrieve them. How to get the list of columns?
Asked
Active
Viewed 503 times
1

ps0604
- 1,227
- 23
- 133
- 330
1 Answers
0
The Query
object model returned by the jOOQ parser API does as of jOOQ 3.12 not provide any corresponding accessors. This feature is however planned for the next minor release (3.13).
The following answer gives you an example how you might be able to use the existing VisitListener
SPI to achieve your goal: https://stackoverflow.com/a/54006668/1732086.

knutwannheden
- 680
- 4
- 7
-
Thanks. `VisitListener` didn't work for me, so I tried to use reflection with the apache commons library: `java.lang.reflect.Field f = FieldUtils.getField(Query.class, "select", true);` I can see in the result the column names, but I cannot cast it How to get the list from `f` ? SelectFieldList class is not public or I cannot use it. – ps0604 Sep 13 '19 at 14:41
-
I also tried Java reflection with `Field f = Query.class.getDeclaredField("select");` but cannot get the values from f as I'm not sure what class to cast. – ps0604 Sep 13 '19 at 14:52
-
I solved it: I did a toString() of the result and split it. – ps0604 Sep 13 '19 at 15:13