I'm trying to parse SQL statements and extract table names using JOOQ's parser. The problem is, the Query and SelectQuery don't seem to provide a public getter for the parsed table list.
val parser = DSL.using(SQLDialect.POSTGRES_10).parser()val queries = parser.parse("SELECT foo, bar FROM mytable WHERE id = 1;")for (query in queries) {when (query) {is SelectQuery<*> -> println(query.fields().map { it.name }) // can find the fields, but not the tableselse -> println(query)}}I could indeed help myself accessing the private field using reflection, but I wonder if there is an easier way:
val field = query.javaClass.getDeclaredField("from")field.isAccessible = trueprintln(field.get(query))And of course, this should also work for other statements (e.g. Insert, update, delete).
--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/bcdbd88d-a3e0-401e-b4be-22b759a35c70%40googlegroups.com.