public string Format(UserDefinedFunction udf)
        {
            var server = udf.CreateWrapper();
            var values = new Dictionary <string, object>(StringComparer.InvariantCultureIgnoreCase)
            {
                { Const.Catalog, udf.Parent.Name },
                { Const.Schema, udf.Schema },
                { Const.Name, udf.Name },
                { Const.NameEscaped, udf.Name.EscapeName() },
                { Const.Body, udf.TextBody },
                { Const.Header, udf.ScriptHeader(true) },
                { Const.Needs, GetNeeds(server, udf, DatabaseObjectTypes.StoredProcedure | DatabaseObjectTypes.UserDefinedFunction | DatabaseObjectTypes.View) ?? string.Empty }
            };

            switch (udf.FunctionType)
            {
            case UserDefinedFunctionType.Inline:
                values[Const.FuncType] = Const.FuncInline;
                break;

            case UserDefinedFunctionType.Table:
                values[Const.FuncType] = Const.FuncMulti;
                break;

            default:
                values[Const.FuncType] = Const.FuncScalar;
                break;
            }

            return(Const.Script.UserDefinedFunction.Format().With(values));
        }
        private void GenerateFunctionScript(UserDefinedFunction function, bool isModifyScript)
        {
            var scriptBuilder = new StringBuilder();

            try
            {
                scriptBuilder.Append(function.ScriptHeader(isModifyScript));
                scriptBuilder.Append(function.TextBody);
                ResultService.ResultWithNoErrors(scriptBuilder.ToString(), function.Parent.Name);
            }
            catch (Exception e)
            {
                ResultService.ResultWithException(true, e.Message);
            }
        }
Exemple #3
0
        public static void OpenFunctionForModification(UserDefinedFunction userDefinedFunction, SqlConnectionInfo connInfo, HuntingDog.Config.EAlterOrCreate alterOrCreate)
        {
            try
            {
                var builder = new StringBuilder(1000);

                lock (userDefinedFunction)
                {
                    userDefinedFunction.Refresh();

                    builder.AppendLine(UseDataBaseGo(userDefinedFunction.Parent));
                    builder.Append(userDefinedFunction.ScriptHeader(alterOrCreate == EAlterOrCreate.Alter));
                    builder.Append(userDefinedFunction.TextBody);
                }

                CreateSQLDocumentWithHeader(builder.ToString(), connInfo);
            }
            catch (Exception ex)
            {
                log.Error("OpenFunctionForModification failed.", ex);
            }
        }
        public string Format(UserDefinedFunction udf)
        {
            var server = udf.CreateWrapper();
            var values = new Dictionary<string, object>(StringComparer.InvariantCultureIgnoreCase)
            {
                { Const.Catalog, udf.Parent.Name },
                { Const.Schema, udf.Schema },
                { Const.Name, udf.Name },
                { Const.NameEscaped, udf.Name.EscapeName() },
                { Const.Body, udf.TextBody },
                { Const.Header, udf.ScriptHeader(true) },
                { Const.Needs, GetNeeds(server, udf, DatabaseObjectTypes.StoredProcedure | DatabaseObjectTypes.UserDefinedFunction | DatabaseObjectTypes.View) ?? string.Empty }
            };

            switch (udf.FunctionType)
            {
                case UserDefinedFunctionType.Inline:
                    values[Const.FuncType] = Const.FuncInline;
                    break;
                case UserDefinedFunctionType.Table:
                    values[Const.FuncType] = Const.FuncMulti;
                    break;
                default:
                    values[Const.FuncType] = Const.FuncScalar;
                    break;
            }

            return Const.Script.UserDefinedFunction.Format().With(values);
        }