001package gudusoft.gsqlparser.stmt; 002 003 004import gudusoft.gsqlparser.EDbObjectType; 005import gudusoft.gsqlparser.EDbVendor; 006import gudusoft.gsqlparser.ESqlStatementType; 007import gudusoft.gsqlparser.TCustomSqlStatement; 008import gudusoft.gsqlparser.nodes.*; 009 010import java.util.ArrayList; 011 012public class TDropFunctionStmt extends TCustomSqlStatement { 013 014 public TDropFunctionStmt(EDbVendor dbvendor) { 015 super(dbvendor); 016 sqlstatementtype = ESqlStatementType.sstdropfunction; 017 } 018 019 private TObjectName functionName = null; 020 021 public TObjectName getFunctionName() { 022 return functionName; 023 } 024 025 public int doParseStatement(TCustomSqlStatement psql) { 026 if (rootNode == null) return -1; 027 super.doParseStatement(psql); 028 if (rootNode instanceof TDummy){ 029 TDummy node = (TDummy) rootNode; 030 this.functionName = (TObjectName) node.node1; 031 if (this.functionName != null){ 032 this.functionName.setDbObjectType(EDbObjectType.function); 033 } 034 }else if (rootNode instanceof TDropFunctionSqlNode){ 035 // sql server,presto 036 TDropFunctionSqlNode sqlNode = (TDropFunctionSqlNode)rootNode; 037 if (sqlNode.getFunctionNameList() != null){ 038 this.functionName = sqlNode.getFunctionNameList().getObjectName(0); 039 }else{ 040 this.functionName = sqlNode.getFunctionName(); 041 } 042 // postgresql 043 functions = sqlNode.getFunctions(); 044 if (functions != null){ 045 this.functionName = functions.get(0).getFunctionName(); 046 } 047 048 if (this.functionName != null){ 049 this.functionName.setDbObjectType(EDbObjectType.function); 050 } 051 052 } 053 054 055 056 return 0; 057 } 058 059 public ArrayList<TFunctionHeader> getFunctions() { 060 return functions; 061 } 062 063 private ArrayList<TFunctionHeader> functions; 064 065 public void accept(TParseTreeVisitor v) { 066 v.preVisit(this); 067 v.postVisit(this); 068 } 069 070 public void acceptChildren(TParseTreeVisitor v) { 071 v.preVisit(this); 072 v.postVisit(this); 073 } 074}