001package gudusoft.gsqlparser.stmt.mysql; 002 003import gudusoft.gsqlparser.*; 004import gudusoft.gsqlparser.nodes.TIfSqlNode; 005import gudusoft.gsqlparser.nodes.TExpression; 006import gudusoft.gsqlparser.nodes.TElseIfSqlNodeList; 007import gudusoft.gsqlparser.nodes.TParseTreeVisitor; 008 009public class TMySQLIfStmt extends TCustomMySQLStmt { 010 public TMySQLIfStmt (EDbVendor dbvendor){ 011 super(dbvendor); 012 sqlstatementtype = ESqlStatementType.sstmysqlifstmt ; 013 } 014 015 void buildsql() { 016 } 017 018 void clear() { 019 } 020 021 String getasprettytext() { 022 return ""; 023 } 024 025 void iterate(TVisitorAbs pvisitor) { 026 } 027 028 public int doParseStatement(TCustomSqlStatement psql) { 029 if (rootNode == null) return -1; 030 TIfSqlNode ifSqlNode = (TIfSqlNode)rootNode; 031 super.doParseStatement(psql); 032 this.condition = ifSqlNode.getCondition(); 033 if (ifSqlNode.getThenStmts() != null){ 034 ifSqlNode.getThenStmts().doParse(this,ESqlClause.unknown); 035 for(int i=0;i<ifSqlNode.getThenStmts().size();i++){ 036 this.getThenStmts().add(ifSqlNode.getThenStmts().getStatementSqlNode(i).getStmt()); 037 } 038 } 039 040 if (ifSqlNode.getElseIfList() != null){ 041 ifSqlNode.getElseIfList().doParse(this,ESqlClause.unknown); 042 this.elseIfList = ifSqlNode.getElseIfList(); 043 } 044 045 if (ifSqlNode.getElseStmts() != null){ 046 ifSqlNode.getElseStmts().doParse(this,ESqlClause.unknown); 047 for(int i=0;i<ifSqlNode.getElseStmts().size();i++){ 048 this.getDefaultStmts().add(ifSqlNode.getElseStmts().getStatementSqlNode(i).getStmt()); 049 } 050 } 051 052 return 0; 053 } 054 055 private TExpression condition = null; 056 057 public TExpression getCondition() { 058 return condition; 059 } 060 061 private TStatementList thenStmts = null; 062 private TStatementList defaultStmts = null; 063 064 public TStatementList getDefaultStmts() { 065 if (this.defaultStmts == null){ 066 this.defaultStmts = new TStatementList(); 067 } 068 return defaultStmts; 069 } 070 071 public TStatementList getThenStmts() { 072 if (this.thenStmts == null){ 073 this.thenStmts = new TStatementList(); 074 } 075 return thenStmts; 076 } 077 078 private TElseIfSqlNodeList elseIfList = null; 079 080 public TElseIfSqlNodeList getElseIfList() { 081 return elseIfList; 082 } 083 084 public void accept(TParseTreeVisitor v){ 085 v.preVisit(this); 086 v.postVisit(this); 087 } 088 089 public void acceptChildren(TParseTreeVisitor v){ 090 v.preVisit(this); 091 condition.accept(v); 092 if (thenStmts != null) thenStmts.accept(v); 093 if (elseIfList != null) elseIfList.accept(v); 094 if (defaultStmts != null) defaultStmts.accept(v); 095 v.postVisit(this); 096 } 097 098 public void setCondition(TExpression condition) { 099 this.condition = condition; 100 } 101 102 public void setThenStmts(TStatementList thenStmts) { 103 this.thenStmts = thenStmts; 104 } 105 106 public void setDefaultStmts(TStatementList defaultStmts) { 107 this.defaultStmts = defaultStmts; 108 } 109 110 public void setElseIfList(TElseIfSqlNodeList elseIfList) { 111 this.elseIfList = elseIfList; 112 } 113}