001package gudusoft.gsqlparser.stmt; 002 003import gudusoft.gsqlparser.*; 004import gudusoft.gsqlparser.nodes.TExpression; 005import gudusoft.gsqlparser.nodes.TExpressionList; 006import gudusoft.gsqlparser.nodes.TParseTreeVisitor; 007import gudusoft.gsqlparser.nodes.TReturnSqlNode; 008 009/** 010 * The RETURN statement immediately completes the execution of a subprogram and returns control to the invoker 011 * 012 * 013 */ 014 015public class TReturnStmt extends TCustomSqlStatement { 016 public TReturnStmt(){ 017 this(EDbVendor.dbvoracle); 018 } 019 020 public TReturnStmt(EDbVendor dbvendor){ 021 super(dbvendor); 022 sqlstatementtype = ESqlStatementType.sst_returnstmt; 023 } 024 025 void buildsql() { 026 } 027 028 void clear() { 029 } 030 031 String getasprettytext() { 032 return ""; 033 } 034 035 void iterate(TVisitorAbs pvisitor) { 036 } 037 038 /** 039 * A combination of variables, constants, literals, operators, and function calls. The 040 * simplest expression consists of a single variable. When the RETURN statement is 041 * executed, the value of expression is assigned to the function identifier. 042 * @return 043 */ 044 public TExpression getExpression() { 045 return expression; 046 } 047 048 private TExpression expression = null; 049 050 public void init(Object arg1) 051 { 052 expression = (TExpression)arg1; 053 } 054 055 public int doParseStatement(TCustomSqlStatement psql) { 056 super.doParseStatement(psql); 057 switch (dbvendor){ 058 case dbvmysql: 059 if (rootNode == null) return -1; 060 TReturnSqlNode returnSqlNode = (TReturnSqlNode)rootNode; 061 062 063 if (returnSqlNode.getExpr() != null){ 064 this.expression = returnSqlNode.getExpr(); 065 } 066 break; 067 case dbvoceanbase: 068 // MySQL/system tenant: the MySQL RETURN (Mantis 4813); Oracle tenant unchanged 069 if (isMySQLDialect()){ 070 if (rootNode == null) return -1; 071 TReturnSqlNode obReturnSqlNode = (TReturnSqlNode)rootNode; 072 if (obReturnSqlNode.getExpr() != null){ 073 this.expression = obReturnSqlNode.getExpr(); 074 } 075 } 076 break; 077 default: 078 break; 079 } 080 081 if (expression != null){ 082 expression.doParse(this,ESqlClause.unknown); 083 } 084 if (usingVariables != null){ 085 usingVariables.doParse(this,ESqlClause.unknown); 086 } 087 088 return 0; 089 } 090 091 public void accept(TParseTreeVisitor v){ 092 v.preVisit(this); 093 v.postVisit(this); 094 } 095 public void acceptChildren(TParseTreeVisitor v){ 096 v.preVisit(this); 097 if (expression != null){ 098 expression.acceptChildren(v); 099 } 100 if (usingVariables != null){ 101 usingVariables.acceptChildren(v); 102 } 103 v.postVisit(this); 104 } 105 106 public void setExpression(TExpression expression) { 107 this.expression = expression; 108 } 109 110 private TExpressionList usingVariables = null; 111 112 /** 113 * The values a PL/pgSQL {@code RETURN QUERY EXECUTE command-string USING expression [, ...]} binds to the 114 * placeholders {@code $1}, {@code $2}, ... of its command text; null without a USING clause. 115 * @return the USING expressions, in order 116 */ 117 public TExpressionList getUsingVariables() { 118 return usingVariables; 119 } 120 121 public void setUsingVariables(TExpressionList usingVariables) { 122 this.usingVariables = usingVariables; 123 } 124}