コード例 #1
0
        private void ParseFunction(CreateFunctionContext node)
        {
            FullIdContext id = node.fullId();

            UidContext[] uids = id.uid();

            List <string> names = new List <string>();

            foreach (UidContext uid in uids)
            {
                string name = uid.simpleId().GetText();
                names.Add(name);
            }

            this.WriteKeyValue("Function", string.Join(".", names));

            this.WriteBeginBrace();

            string dataType = node.dataType().GetText();

            this.WriteKeyValue("dataType", dataType);

            FunctionParameterContext[] parameters = node.functionParameter();

            foreach (FunctionParameterContext parameter in parameters)
            {
                string name         = parameter.uid().GetText();
                string paraDataType = parameter.dataType().GetText();

                this.WriteKeyValue("parameter", $"{name} {paraDataType}");
            }

            RoutineBodyContext body = node.routineBody();

            this.WriteLine("body");

            this.WriteBeginBrace(2);

            this.indent = 4;

            BlockStatementContext block = body.blockStatement();

            foreach (IParseTree blockChild in block.children)
            {
                if (blockChild is ProcedureSqlStatementContext procedure)
                {
                    this.ParseProcedureStatement(procedure);
                }
                else
                {
                    string text = blockChild.GetText();

                    this.WriteLine(text, indent);
                }
            }

            this.WriteEndBrace(2);

            this.WriteEndBrace();
        }
コード例 #2
0
        public override AnalyseResult AnalyseFunction(string content)
        {
            SqlSyntaxError error = null;

            DdlStatementContext ddlStatement = this.GetDdlStatementContext(content, out error);

            AnalyseResult result = new AnalyseResult()
            {
                Error = error
            };

            if (!result.HasError && ddlStatement != null)
            {
                RoutineScript script = new RoutineScript()
                {
                    Type = RoutineType.FUNCTION
                };

                CreateFunctionContext func = ddlStatement.createFunction();

                if (func != null)
                {
                    #region Name
                    this.SetScriptName(script, func.fullId());
                    #endregion

                    #region Parameters
                    FunctionParameterContext[] parameters = func.functionParameter();

                    if (parameters != null)
                    {
                        foreach (FunctionParameterContext parameter in parameters)
                        {
                            Parameter parameterInfo = new Parameter();

                            UidContext uid = parameter.uid();

                            parameterInfo.Name = new TokenInfo(uid)
                            {
                                Type = TokenType.ParameterName
                            };

                            parameterInfo.DataType = new TokenInfo(parameter.dataType().GetText())
                            {
                                Type = TokenType.DataType
                            };

                            this.SetParameterType(parameterInfo, parameter.children);

                            script.Parameters.Add(parameterInfo);
                        }
                    }
                    #endregion

                    script.ReturnDataType = new TokenInfo(func.dataType().GetText())
                    {
                        Type = TokenType.DataType
                    };

                    #region Body

                    this.SetScriptBody(script, func.routineBody());

                    #endregion
                }

                this.ExtractFunctions(script, ddlStatement);

                result.Script = script;
            }

            return(result);
        }