How to get columns in Where clause

Help
Anonymous
2012-07-20
2012-12-07

  • Anonymous
    2012-07-20

    Hello,

    I am stuck trying to figure out how to get the columns from the Where clause.  Ultimately I need to update them.  Appreciate any help.

    Thank you.

     
  • christian
    christian
    2012-10-02

    I think you have to drill down every expression one by one in the tree.

    public static void main(String args) throws JSQLParserException {
    // TODO Auto-generated method stub
    String statement = "SELECT a,b,c FROM mytable WHERE mytable.col = 9 and b=c LIMIT 3, ?";
    //statement = SampleSQL1.sql;

    CCJSqlParserManager parserManager = new CCJSqlParserManager();
    Select select = (Select) parserManager.parse(new StringReader(statement));

    PlainSelect ps = (PlainSelect) select.getSelectBody();

    System.out.println(ps.getWhere().toString());
    System.out.println(ps.getSelectItems().get(1).toString());

                    // here you have to check what kind of expression it is and execute your actions individualy for every expression implementation
    AndExpression e = (AndExpression) ps.getWhere();
    System.out.println(e.getLeftExpression());  // whitch is another expression you can drill down
    }

    Chris