JSqlParser parses an SQL statement and translate it into a hierarchy of Java classes. The generated hierarchy can be navigated using the Visitor Pattern
@AnEmortalKid any reading material? something like user guide for this? I'm kinda overwhelmed actually because there are so many features hahaha
@wumpz btw sir, I got a bit problem for example in query like "select avg(a), b from table1;". I know I can get the "avg(a)" and "b". While avg(a) should be casted to Function and b casted to Column. Is there any way to know whats it type (function or column) from SelectExpressionItem class. Well actually I can check it manually using regex, but I guess this library already has the function to do this but I can't find it. And is there any official docs or user guide for this library other than the git wiki? Thanks alot!
class Whatever {
main(String[] args) {
String sql = "Select * from TAB1";
StatementVisitor vs = new MyVisitor();
vs.accept(CCSQlutilParser.parse(sql));
}
class MyVisitor implements StatementVisitor
// other methods ommitted
visit(Select select) {
SelectBody sb = select.getBody();
System.out.println("SB:" + sb);
visit(sb);
}
visit(SelectBody sb) {
// do something with whatever, call visit if it's another element type
}
}
}
}