Menu

Need help in understanding jsqlparser

2010-10-26
2012-12-07
  • Nobody/Anonymous

    I am new to jsqlparser. I have just downloaded the jar and was trying to run examples.

    I have one sql query as following:
    SELECT *
    FROM
          (SELECT
                   MNGR_NUM,
                   (CASE
                      WHEN MNGR_NUM = 0 THEN '   '
                      WHEN MNGR_NUM > 1 THEN '%'
                      ELSE (SELECT MNGR
                            FROM SUMMIT.MNGR
                            WHERE MNGR = '$Manager ID$')
                    END) AS ID
           FROM
                 (SELECT COUNT(*) AS MNGR_NUM
                  FROM SUMMIT.MNGR
                  WHERE MNGR LIKE '$Manager ID$') T1) T2
    Now I want jsqlparser to get the complete detail information in any class.

    I have tries using following code:

    CCJSqlParserManager parserManager = new CCJSqlParserManager();
    PlainSelect plainSelect = (PlainSelect) ((Select) parserManager.parse(new StringReader(queryinfile))).getSelectBody();
    System.out.println(""+plainSelect.getWhere());

    But plainSelect.getWhere() returns null in this case.

    What I want to achieve is programmatically find '$Manager ID$' and if I don’t have any value for '$Manager ID$' I need to remove the corresponding to condition from WHERE clause.

    Can you please help me in achieving this by using jsql parser classes?

    Please respond.

    Thanks in advance.

     
  • Leonardo Francalanci

    You are looking in the wrong place. The outer select doesn't have any WHERE clause: that's why plainSelect.getWhere() returns null.

    You have to look into the fromItem of the selectBody of the first PlainSelect, then its fromItem (which is again a SubSelect); then the selectBody: there you'll find the where (a LikeExpression) you're looking for.

    It will be much easier if you use a debugger and look at plainSelect using a watch expression….

     

Log in to post a comment.