001package gudusoft.gsqlparser.stmt; 002 003import gudusoft.gsqlparser.*; 004import gudusoft.gsqlparser.nodes.TExpression; 005import gudusoft.gsqlparser.nodes.TParseTreeVisitor; 006import gudusoft.gsqlparser.nodes.TReturnSqlNode; 007 008/** 009 * The RETURN statement immediately completes the execution of a subprogram and returns control to the invoker 010 * 011 * 012 */ 013 014public class TReturnStmt extends TCustomSqlStatement { 015 public TReturnStmt(){ 016 this(EDbVendor.dbvoracle); 017 } 018 019 public TReturnStmt(EDbVendor dbvendor){ 020 super(dbvendor); 021 sqlstatementtype = ESqlStatementType.sst_returnstmt; 022 } 023 024 void buildsql() { 025 } 026 027 void clear() { 028 } 029 030 String getasprettytext() { 031 return ""; 032 } 033 034 void iterate(TVisitorAbs pvisitor) { 035 } 036 037 /** 038 * A combination of variables, constants, literals, operators, and function calls. The 039 * simplest expression consists of a single variable. When the RETURN statement is 040 * executed, the value of expression is assigned to the function identifier. 041 * @return 042 */ 043 public TExpression getExpression() { 044 return expression; 045 } 046 047 private TExpression expression = null; 048 049 public void init(Object arg1) 050 { 051 expression = (TExpression)arg1; 052 } 053 054 public int doParseStatement(TCustomSqlStatement psql) { 055 super.doParseStatement(psql); 056 switch (dbvendor){ 057 case dbvmysql: 058 if (rootNode == null) return -1; 059 TReturnSqlNode returnSqlNode = (TReturnSqlNode)rootNode; 060 061 062 if (returnSqlNode.getExpr() != null){ 063 this.expression = returnSqlNode.getExpr(); 064 } 065 break; 066 default: 067 break; 068 } 069 070 if (expression != null){ 071 expression.doParse(this,ESqlClause.unknown); 072 } 073 074 return 0; 075 } 076 077 public void accept(TParseTreeVisitor v){ 078 v.preVisit(this); 079 v.postVisit(this); 080 } 081 public void acceptChildren(TParseTreeVisitor v){ 082 v.preVisit(this); 083 if (expression != null){ 084 expression.acceptChildren(v); 085 } 086 v.postVisit(this); 087 } 088 089 public void setExpression(TExpression expression) { 090 this.expression = expression; 091 } 092}