001package gudusoft.gsqlparser.stmt.mssql;
002
003import gudusoft.gsqlparser.*;
004import gudusoft.gsqlparser.stmt.TCreateFunctionStmt;
005
006/**
007 * SQL Server/ Sybase  create function.
008 *
009 *
010 */
011public class TMssqlCreateFunction extends TCreateFunctionStmt {
012
013    public TMssqlCreateFunction (EDbVendor dbvendor){
014        super(dbvendor);
015        sqlstatementtype = ESqlStatementType.sstmssqlcreatefunction ;
016        }
017
018}
019
020//public class TMssqlCreateFunction extends TStoredProcedureSqlStatement{
021//
022//    private TMssqlBlock block = null;
023//    private TMssqlReturn returnStmt = null;
024//    private TPTNodeList <TProcedureOption> procedureOptions;
025//    private TObjectName returnTableVaraible = null;
026//    private TTableElementList returnTableDefinitions = null;
027//    private TTypeName returnDataType = null;
028//    private int functionType = TBaseType.uftScalar;
029//
030//
031//    public void setProcedureOptions(TPTNodeList<TProcedureOption> procedureOptions) {
032//        this.procedureOptions = procedureOptions;
033//    }
034//
035//    public TPTNodeList<TProcedureOption> getProcedureOptions() {
036//        return procedureOptions;
037//    }
038//
039//
040//    public TMssqlCreateFunction (EDbVendor dbvendor){
041//        super(dbvendor);
042//        sqlstatementtype = ESqlStatementType.sstmssqlcreatefunction ;
043//        }
044//
045//    void buildsql() {
046//    }
047//
048//    void clear() {
049//    }
050//
051//    String getasprettytext() {
052//        return "";
053//    }
054//
055//    void iterate(TVisitorAbs pvisitor) {
056//    }
057//
058//    private TObjectName functionName = null;
059//    public TObjectName getStoredProcedureName(){
060//        return functionName;
061//    }
062//    /**
063//     * The name that you give to the function that you are declaring or defining.
064//     * @return
065//     */
066//    public TObjectName getFunctionName() {
067//        return functionName;
068//    }
069//
070//
071//    private EFunctionReturnsType returnsType = EFunctionReturnsType.frtScalar;
072//
073//    public EFunctionReturnsType getReturnsType() {
074//        return returnsType;
075//    }
076//
077//    private int returnMode = TBaseType.function_return_datatype;
078//
079//    /**
080//     * @deprecated As of v2.0.4.8, please use {@link #getReturnsType()} instead
081//     *
082//     * create function of sql server may return normal datatype, or return TABLE, or TABLE with variable
083//     * <p>TBaseType.function_return_datatype
084//     * <p>TBaseType.function_return_table
085//     * <p>TBaseType.function_return_table_variable
086//     * <p> if return mode is TBaseType.function_return_datatype, check datatype in returnDataType
087//     * <p>if return mode is TBaseType.function_return_table_variable, check returnTableVaraible and tableDefinitions.
088//     *
089//     * @return returns type
090//     */
091//    public int getReturnMode() {
092//        return returnMode;
093//    }
094//
095//
096//    /**
097//     *
098//     * @return statements in create function
099//     */
100//    public TMssqlBlock getBlock() {
101//        return block;
102//    }
103//
104//
105//    /**
106//     *
107//     * @return this is the only return statement in create function.
108//     */
109//    public TMssqlReturn getReturnStmt() {
110//        return returnStmt;
111//    }
112//
113//    public TObjectName getReturnTableVaraible() {
114//        return returnTableVaraible;
115//    }
116//
117//    /**
118//     * when {@link #getReturnsType()} == {@link EFunctionReturnsType#frtMultiStatementTableValue}
119//     * returns this table_type_definition
120//     *
121//     * @return table_type_definition
122//     */
123//    public TTableElementList getReturnTableDefinitions() {
124//        return returnTableDefinitions;
125//    }
126//    public TTypeName getReturnDataType() {
127//        return returnDataType;
128//    }
129//
130//
131//    /**
132//     * this is used for backward compatibility  of .NET version TMssqlCreateFunction.functiontype
133//     * please use {@link #returnMode} in java version
134//     * @return
135//     */
136//    public int getFunctionType() {
137//        int ret = this.functionType;
138//        if (this.returnMode == TBaseType.function_return_table_variable){
139//            ret = TBaseType.uftMultiStatementTableValued;
140//        }else if (this.returnMode == TBaseType.function_return_table){
141//            ret = TBaseType.uftInlineTableValued;
142//        }
143//        return ret;
144//    }
145//
146//    public int doParseStatement(TCustomSqlStatement psql) {
147//        if (rootNode == null) return -1;
148//        if(!(rootNode instanceof TCreateFunctionSqlNode)) return -1;
149//        TCreateFunctionSqlNode createFunctionNode = (TCreateFunctionSqlNode)rootNode;
150//        super.doParseStatement(psql);
151//
152//        TStackFrame stackFrame = new TStackFrame(this.stmtScope);
153//        stackFrame.pushStack(getFrameStack());
154//
155//
156//        functionName = createFunctionNode.getFunctionName();
157//        if (getSqlEnv() != null)  {
158//            getSqlEnv().addFunction(functionName.toString(),true);
159//            if (getSqlEnv().getDefaultCatalogName() != null){
160//                if (functionName.getDatabaseToken() == null){
161//                    functionName.setDatabaseToken(new TSourceToken(getSqlEnv().getDefaultCatalogName()));
162//                }
163//            }
164//        }
165//        procedureOptions = createFunctionNode.getProcedureOptions();
166//
167//        this.setParameterDeclarations(createFunctionNode.getParameters());
168//
169//        if (createFunctionNode.getReturnDataType() != null){
170//            this.returnMode = TBaseType.function_return_datatype;
171//            this.returnDataType = createFunctionNode.getReturnDataType();
172//            this.returnsType = EFunctionReturnsType.frtScalar;
173//        }else if (createFunctionNode.getReturnTable() != null){
174//            TDummy dmy = createFunctionNode.getReturnTable();
175//            if (dmy.node1 != null){
176//                this.returnsType = EFunctionReturnsType.frtMultiStatementTableValue;
177//                this.returnMode = TBaseType.function_return_table_variable;
178//                this.returnTableVaraible = (TObjectName)dmy.node1;
179//                this.returnTableVaraible.setObjectType(TObjectName.ttobjVariable);
180//                this.returnTableDefinitions = (TTableElementList)dmy.list1;
181//                this.returnTableDefinitions.doParse(this,ESqlClause.unknown);
182//
183//                if (getSqlEnv() != null)  {
184//                      TSQLTable returnTable = getSqlEnv().addTable(this.returnTableVaraible.toString(),true);
185//                      TSQLFunction functionTable = getSqlEnv().searchFunction(functionName.toString());
186//                      for(TTableElement column: this.returnTableDefinitions){
187//                              if(column.getColumnDefinition()!=null && column.getColumnDefinition().getColumnName()!=null){
188//                                      returnTable.addColumn(column.getColumnDefinition().getColumnName().toString());
189//                                      functionTable.addReturnColumn(column.getColumnDefinition().getColumnName().toString());
190//                              }
191//                      }
192//                }
193//            }else{
194//                this.returnMode = TBaseType.function_return_table;
195//                this.returnsType = EFunctionReturnsType.frtInlineTableValue;
196//            }
197//        }
198//
199//
200//        // push parameterDeclarations into symbolTable
201//        if (this.getParameterDeclarations() != null){
202//            for(int i=0;i< this.getParameterDeclarations().size();i++){
203//               this.getTopStatement().getSymbolTable().push( new TSymbolTableItem(TObjectName.ttobjParameter,this, this.getParameterDeclarations().getParameterDeclarationItem(i)));
204//               if (this.getParameterDeclarations().getParameterDeclarationItem(i).getParameterName() != null){
205//                   this.stmtScope.addSymbol(new TVariable(this.getParameterDeclarations().getParameterDeclarationItem(i).getParameterName(),this.getParameterDeclarations().getParameterDeclarationItem(i)));
206//               }
207//            }
208//        }
209//
210//        if (createFunctionNode.getBlcok() != null){
211//            block = new TMssqlBlock(this.dbvendor);
212//            block.rootNode = createFunctionNode.getBlcok();
213//            block.doParseStatement(this);
214//            this.getBodyStatements().add(block);
215//        }
216//
217//        if (createFunctionNode.getReturnSqlNode() != null){
218//            returnStmt = new TMssqlReturn(this.dbvendor);
219//            returnStmt.rootNode = createFunctionNode.getReturnSqlNode();
220//            returnStmt.doParseStatement(this);
221//            this.getBodyStatements().add(returnStmt);
222//        }
223//
224//        // pop parameterDeclarations from symbolTable
225//        if (this.getParameterDeclarations() != null){
226//            for(int i=0;i< this.getParameterDeclarations().size();i++){
227//               this.getTopStatement().getSymbolTable().pop();
228//            }
229//        }
230//
231//        stackFrame.popStack(getFrameStack());
232//
233//        return 0;
234//    }
235//
236//    public void accept(TParseTreeVisitor v){
237//        v.preVisit(this);
238//        v.postVisit(this);
239//    }
240//
241//    public void acceptChildren(TParseTreeVisitor v){
242//        v.preVisit(this);
243//        if (this.getParameterDeclarations() != null) getParameterDeclarations().acceptChildren(v);
244//        if (getBodyStatements().size() > 0) getBodyStatements().acceptChildren(v);
245//        if (returnStmt != null) returnStmt.acceptChildren(v);
246//        v.postVisit(this);
247//    }
248//
249//    public void setFunctionName(TObjectName functionName) {
250//        this.functionName = functionName;
251//    }
252//
253//    public void setBlock(TMssqlBlock block) {
254//        this.block = block;
255//    }
256//    public void setReturnStmt(TMssqlReturn returnStmt) {
257//        this.returnStmt = returnStmt;
258//    }
259//    public void setReturnMode(int returnMode) {
260//        this.returnMode = returnMode;
261//    }
262//    public void setReturnTableVaraible(TObjectName returnTableVaraible) {
263//        this.returnTableVaraible = returnTableVaraible;
264//    }
265//    public void setReturnTableDefinitions(TTableElementList returnTableDefinitions) {
266//        this.returnTableDefinitions = returnTableDefinitions;
267//    }
268//    public void setReturnDataType(TTypeName returnDataType) {
269//        this.returnDataType = returnDataType;
270//    }
271//    public void setFunctionType(int functionType) {
272//        this.functionType = functionType;
273//    }
274//}