001package gudusoft.gsqlparser.nodes;
002
003import gudusoft.gsqlparser.*;
004
005
006public class TWhereClause extends TParseTreeNode {
007
008    private boolean curerntOf = false;
009
010    public TWhereClause(){
011    }
012
013    public TWhereClause(String text){
014        this();
015        this.setText(text);
016    }
017
018    public void setCurerntOf(boolean curerntOf) {
019        this.curerntOf = curerntOf;
020        if ((this.condition != null)&&(this.condition.getExpressionType() == EExpressionType.simple_object_name_t)){
021            this.condition.getObjectOperand().setDbObjectType(EDbObjectType.cursor);
022        }
023    }
024
025    public boolean isCurerntOf() {
026
027        return curerntOf;
028    }
029
030    public void setText(String nodeText){
031        String whereStr = nodeText.trim();
032        if (whereStr.toLowerCase().startsWith("where")){
033            whereStr = whereStr.substring(5);
034        }
035        TExpression e = TGSqlParser.parseExpression(TGSqlParser.currentDBVendor,whereStr);
036        if (e == null){
037            super.setText("\nwhere "+whereStr);
038        }else{
039            this.condition = e;
040
041            TSourceToken newLineToken = new TSourceToken("\n");
042            TSourceToken whereToken = new TSourceToken("where");
043            TSourceToken spaceToken = new TSourceToken(" ");
044
045            TSourceToken.concatInChain(newLineToken,whereToken);
046            TSourceToken.concatInChain(whereToken,spaceToken);
047            TSourceToken.concatInChain(spaceToken,e.getStartToken());
048
049            super.setText(newLineToken,e.getEndToken());
050        }
051
052    }
053
054    private TExpression condition = null;
055
056    public TExpression getCondition() {
057        return condition;
058    }
059
060    public void init(Object arg1)
061    {
062        condition = (TExpression)arg1;
063    }
064
065    public void setCondition(TExpression condition) {
066        this.condition = condition;
067        if (condition.toString() != null){
068            this.setText(condition.toString());
069        }
070    }
071
072    public void doParse(TCustomSqlStatement psql, ESqlClause plocation){
073        if (!isCurerntOf() )
074            this.condition.doParse(psql,plocation);
075    }
076
077    public void accept(TParseTreeVisitor v){
078        v.preVisit(this);
079        v.postVisit(this);
080    }
081
082    public void acceptChildren(TParseTreeVisitor v){
083        v.preVisit(this);
084        this.condition.acceptChildren(v);
085        v.postVisit(this);
086    }
087
088
089
090}