001package gudusoft.gsqlparser.stmt; 002 003import gudusoft.gsqlparser.*; 004import gudusoft.gsqlparser.nodes.TObjectName; 005import gudusoft.gsqlparser.nodes.TExpressionList; 006import gudusoft.gsqlparser.nodes.TOpenSqlNode; 007import gudusoft.gsqlparser.nodes.TParseTreeVisitor; 008 009/** 010 * The OPEN statement executes the query associated with a cursor. 011 */ 012 013public class TOpenStmt extends TCustomSqlStatement { 014 public TOpenStmt(){ 015 this(EDbVendor.dbvoracle); 016 } 017 public TOpenStmt(EDbVendor dbvendor){ 018 super(dbvendor); 019 sqlstatementtype = ESqlStatementType.sst_openstmt; 020 } 021 022 void buildsql() { 023 } 024 025 void clear() { 026 } 027 028 String getasprettytext() { 029 return ""; 030 } 031 032 void iterate(TVisitorAbs pvisitor) { 033 } 034 035 /** 036 * 037 * @return variables declared as the formal parameter of a cursor. 038 */ 039 public TExpressionList getCursorParameterNames() { 040 return cursorParameterNames; 041 } 042 043 private TExpressionList cursorParameterNames = null; 044 045 /** 046 * 047 * @return An explicit cursor previously declared within the current scope and not currently open. 048 */ 049 public TObjectName getCursorName() { 050 return cursorName; 051 } 052 053 private TObjectName cursorName = null; 054 055 public int doParseStatement(TCustomSqlStatement psql) { 056 super.doParseStatement(psql); 057 switch (dbvendor){ 058 case dbvmysql: 059 if (rootNode == null) return -1; 060 TOpenSqlNode openSqlNode = (TOpenSqlNode)rootNode; 061 this.cursorName = openSqlNode.getCursorName(); 062 break; 063 case dbvoceanbase: 064 // MySQL/system tenant: the MySQL OPEN (Mantis 4813); Oracle tenant unchanged 065 if (isMySQLDialect()){ 066 if (rootNode == null) return -1; 067 TOpenSqlNode obOpenSqlNode = (TOpenSqlNode)rootNode; 068 this.cursorName = obOpenSqlNode.getCursorName(); 069 } 070 break; 071 default: 072 break; 073 } 074 return 0; 075 } 076 077 public void init(Object arg1) 078 { 079 cursorName = (TObjectName)arg1; 080 // this.cursorName.setObjectType(TObjectName.ttobjCursorName); 081 this.cursorName.setDbObjectType(EDbObjectType.cursor); 082 } 083 084 public void init(Object arg1,Object arg2) 085 { 086 init(arg1); 087 cursorParameterNames = (TExpressionList)arg2; 088 } 089 090 public void accept(TParseTreeVisitor v){ 091 v.preVisit(this); 092 v.postVisit(this); 093 } 094 public void acceptChildren(TParseTreeVisitor v){ 095 v.preVisit(this); 096 v.postVisit(this); 097 } 098 099 public void setCursorParameterNames(TExpressionList cursorParameterNames) { 100 this.cursorParameterNames = cursorParameterNames; 101 } 102 103 public void setCursorName(TObjectName cursorName) { 104 this.cursorName = cursorName; 105 } 106}