001package gudusoft.gsqlparser.stmt.mysql; 002 003import gudusoft.gsqlparser.*; 004import gudusoft.gsqlparser.nodes.*; 005import gudusoft.gsqlparser.stmt.TStoredProcedureSqlStatement; 006 007/** 008 * MySQL create function. 009 * 010 * @deprecated since GSP Java version 2.5.1.2, use {@link gudusoft.gsqlparser.stmt.TCreateFunctionStmt} instead. 011 */ 012public class TMySQLCreateFunction extends TStoredProcedureSqlStatement{ 013 public TMySQLCreateFunction (EDbVendor dbvendor){ 014 super(dbvendor); 015 sqlstatementtype = ESqlStatementType.sstmysqlcreatefunction ; 016 } 017 018 void buildsql() { 019 } 020 021 void clear() { 022 } 023 024 String getasprettytext() { 025 return ""; 026 } 027 028 void iterate(TVisitorAbs pvisitor) { 029 } 030 031 public TObjectName getStoredProcedureName(){ 032 return functionName; 033 } 034 035 036 private TTypeName returnDataType = null; 037 038 public TTypeName getReturnDataType() { 039 return returnDataType; 040 } 041 042 043 private TObjectName functionName = null; 044 045 /** 046 * The name that you give to the function that you are declaring or defining. 047 * @return 048 */ 049 public TObjectName getFunctionName() { 050 return functionName; 051 } 052 053 private String sharedLibraryName; 054 055 public String getSharedLibraryName() { 056 return sharedLibraryName; 057 } 058 059 public int doParseStatement(TCustomSqlStatement psql) { 060 if (rootNode == null) return -1; 061 TCreateFunctionSqlNode createFunctionNode = (TCreateFunctionSqlNode)rootNode; 062 super.doParseStatement(psql); 063 064 functionName = createFunctionNode.getFunctionName(); 065 if (getSqlEnv().getDefaultCatalogName() != null){ 066 if (functionName.getDatabaseToken() == null){ 067 functionName.setDatabaseToken(new TSourceToken(getSqlEnv().getDefaultCatalogName())); 068 } 069 } 070 071 this.setParameterDeclarations(createFunctionNode.getParameters()); 072 073 // push parameterDeclarations into symbolTable 074 if (this.getParameterDeclarations() != null){ 075 for(int i=0;i< this.getParameterDeclarations().size();i++){ 076 this.getTopStatement().getSymbolTable().push( new TSymbolTableItem(TObjectName.ttobjParameter,this, this.getParameterDeclarations().getParameterDeclarationItem(i))); 077 } 078 } 079 080 this.returnDataType = createFunctionNode.getReturnDataType(); 081 082 if (createFunctionNode.getStmt() != null){ 083 createFunctionNode.getStmt().doParse(this,ESqlClause.unknown); 084 this.getBodyStatements().add(createFunctionNode.getStmt().getStmt()); 085 } 086 else if (createFunctionNode.getBlcok() != null){ 087 createFunctionNode.getBlcok().getStmts().doParse(this,ESqlClause.unknown); 088 089 for(int i=0;i<createFunctionNode.getBlcok().getStmts().size();i++){ 090 this.getBodyStatements().add(createFunctionNode.getBlcok().getStmts().getStatementSqlNode(i).getStmt()); 091 } 092 093 } 094 095 // pop parameterDeclarations from symbolTable 096 if (this.getParameterDeclarations() != null){ 097 for(int i=0;i< this.getParameterDeclarations().size();i++){ 098 this.getTopStatement().getSymbolTable().pop(); 099 } 100 } 101 102 if (createFunctionNode.getSharedLibraryName() != null){ 103 sharedLibraryName = createFunctionNode.getSharedLibraryName().toString(); 104 } 105 return 0; 106 } 107 108 public void accept(TParseTreeVisitor v){ 109 v.preVisit(this); 110 v.postVisit(this); 111 } 112 113 public void acceptChildren(TParseTreeVisitor v){ 114 v.preVisit(this); 115 if (getParameterDeclarations() != null) getParameterDeclarations().acceptChildren(v); 116 getBodyStatements().acceptChildren(v); 117 v.postVisit(this); 118 } 119 120 public void setReturnDataType(TTypeName returnDataType) { 121 this.returnDataType = returnDataType; 122 } 123 124 public void setFunctionName(TObjectName functionName) { 125 this.functionName = functionName; 126 } 127}