forked from JSQLParser/JSqlParser
-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Simon Koch edited this page Jun 15, 2021
·
1 revision
Welcome to the (unofficial) JSqlParser wiki!
Let's try and make sense on how to use this lib. We are using Scala for this.
val stmt = CCJSqlParserUtil.parse(query)
returns any of net.sf.jsqlparser.statement.{select, insert,...}.{Select, Insert, ...} use your IDE to get the whole selection.
We will continue using stmt to reference the parsed query/statement.
Note: For some reason the only transaction related statement that is supported is 'COMMIT'.
To iterate over the items the query selects the below statement works:
val stmt = stmt.asInstanceOf[Select].getSelectBody().asInstanceOf[PlainSelect].getSelectItems.toArray.map {
case item : SelectExpressionItem => // the basic?? item expression and with toString you can get the name
case _ : AllColumns => //this is the wild card
}
val where = Option(stmt.asInstanceOf[Select].getSelectBody().asInstanceOf[PlainSelect].getWhere)
It seems like the where returns an expression that is the tree representing the expression