Accepted answer

your code does not show what the querydescription class does, but i can guess.

in dealing with the where clause, you are looking for three types of nodes:

  • binarylogicaloperatornode - this has the and, or, is operators that separate the individual clauses in the where clause.
  • binaryoperatornode - this has the individual >, <, and other operations.
  • the constants and column operators.

in your example, you would visit a binaryoperatornode, with a type of lt, and the two children would be constantnode with a value of 5, and a columnreference node with the value of "d".

note: the parser does not connect the column references to the tables in the tables list. this is a separate step in the query processing. so you will have a columnreference node, but no link to which table the column is referencing. the reason is the parser does not have enough information to correctly link the "d" column to the correct table.

this is enough to process the simple query you gave in the example. obviously queries can become much more complex.

the one node i would add to the list of checks in the inlistoperatornode which handles where d in (1,2,3,4).

edit to add:

keep in mind the vistor#visit() method gets called for each and every node in the tree created by the query parser. the visit method will need to check, and set your variables properly, for frombasetable, constantnode, columnreference.

visitor v = new visitor() {
    list<string> fromtable = new arraylist<string>();
    list<string> fields = new arraylist<string>();

    // other visitor methods go here, not copied for conciseness. 

    public visitable visit(visitable arg0) throws standardexception {
        // other code from your visit() method goes here
        if (arg0 instanceof frombasetable) {
           frombasetable table = (frombasetable)arg0;
        } else if (arg0 instanceof columnreference) {
           columnreference column = (columnreference) arg0;
        // remove the call to create querydescription
    public querydescription getquerydescription() {
        return new querydescription(se, fromtable, fields)

then in your main line of code you call:

querydescription description = v.getquerydescription(); 

now if you have other parts of the query you are interested in, you need to add those nodes to the visit method, and capture the part of the node (names, values, etc) you are interested in.

Related Query

More Query from same tag