Ejemplo n.º 1
0
        /// <summary>
        /// <para>SOUNDEX built-in function.</para>
        /// <para>Returns a four-character (SOUNDEX) code to evaluate the similarity of two strings.</para>
        /// </summary>
        /// <param name="argument">Is an alphanumeric expression of character data. argument can be a constant, variable, or column.</param>
        public static SysFn Soundex(FunctionArgument argument)
        {
            argument = argument ?? Designer.Null;

            return(new SysFn((buildContext, buildArgs) =>
            {
                var sql = String.Format(
                    "SOUNDEX({0})",
                    argument.Build(buildContext, buildArgs));
                buildContext.TryTakeException(argument.Exception, "Sys.Soundex");
                return sql;
            }));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// <para>REPLICATE built-in function.</para>
        /// <para>Repeats a string value a specified number of times.</para>
        /// </summary>
        /// <param name="argument1">Is an expression of a character string or binary data type. argument1 can be either character or binary data.</param>
        /// <param name="argument2">Is an expression of any integer type, including bigint.</param>
        public static SysFn Replicate(FunctionArgument argument1, FunctionArgument argument2)
        {
            argument1 = argument1 ?? Designer.Null;
            argument2 = argument2 ?? Designer.Null;

            return(new SysFn((buildContext, buildArgs) =>
            {
                var sql = String.Format(
                    "REPLICATE({0},{1})",
                    argument1.Build(buildContext, buildArgs),
                    argument2.Build(buildContext, buildArgs));
                buildContext.TryTakeException(argument1.Exception, "Sys.Replicate");
                buildContext.TryTakeException(argument2.Exception, "Sys.Replicate");
                return sql;
            }));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// <para>QUOTENAME built-in function.</para>
        /// <para>Returns a Unicode string with the delimiters added to make the input string a valid SQL Server delimited identifier.</para>
        /// </summary>
        /// <param name="argument">Is a string of Unicode character data. argument is sysname and is limited to 128 characters. Inputs greater than 128 characters return NULL.</param>
        /// <param name="quoteCharacter">Is a one-character string to use as the delimiter. Can be a single quotation mark ( ' ), a left or right bracket ( [ ] ), or a double quotation mark ( " ). If quote_character is not specified, brackets are used.</param>
        public static SysFn Quotename(FunctionArgument argument, Designer.QuoteCharacter quoteCharacter = Designer.QuoteCharacter.Brackets)
        {
            argument = argument ?? Designer.Null;

            switch (quoteCharacter)
            {
            case Designer.QuoteCharacter.Brackets:
                return(new SysFn((buildContext, buildArgs) =>
                {
                    var sql = String.Format(
                        "QUOTENAME({0},'[]')",
                        argument.Build(buildContext, buildArgs));
                    buildContext.TryTakeException(argument.Exception, "Sys.Quotename");
                    return sql;
                }));

            case Designer.QuoteCharacter.SingleQuotationMark:
                return(new SysFn((buildContext, buildArgs) =>
                {
                    var sql = String.Format(
                        "QUOTENAME({0},'''')",
                        argument.Build(buildContext, buildArgs));
                    buildContext.TryTakeException(argument.Exception, "Sys.Quotename");
                    return sql;
                }));

            case Designer.QuoteCharacter.DoubleQuotationMark:
                return(new SysFn((buildContext, buildArgs) =>
                {
                    var sql = String.Format(
                        "QUOTENAME({0},'\"')",
                        argument.Build(buildContext, buildArgs));
                    buildContext.TryTakeException(argument.Exception, "Sys.Quotename");
                    return sql;
                }));

            default:
                return(new SysFn((buildContext, buildArgs) =>
                {
                    var sql = String.Format(
                        "QUOTENAME({0},'[]')",
                        argument.Build(buildContext, buildArgs));
                    buildContext.TryTakeException(argument.Exception, "Sys.Quotename");
                    return sql;
                }));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// <para>COAELSCE built-in function.</para>
        /// <para>Returns the first non-null expression among its arguments.</para>
        /// </summary>
        /// <param name="argument1">Is the first expression of any type.</param>
        /// <param name="argument2">Is the second expression of any type.</param>
        /// <param name="otherArguments">Are all other expressions of any type.</param>
        public static SysFn Coalesce(FunctionArgument argument1, FunctionArgument argument2,
                                     params FunctionArgument[] otherArguments)
        {
            if (argument1 == null)
            {
                argument1 = Designer.Null;
            }
            if (argument2 == null)
            {
                argument2 = Designer.Null;
            }

            if (otherArguments == null || otherArguments.Length == 0)
            {
                return(new SysFn((buildContext, buildArgs) =>
                {
                    var sql = String.Format(
                        "COALESCE({0},{1})",
                        argument1.Build(buildContext, buildArgs),
                        argument2.Build(buildContext, buildArgs));
                    buildContext.TryTakeException(argument1.Exception, "Sys.Coalesce");
                    buildContext.TryTakeException(argument2.Exception, "Sys.Coalesce");
                    return sql;
                }));
            }
            else
            {
                return(new SysFn((buildContext, buildArgs) =>
                {
                    var sql = String.Format(
                        "COALESCE({0},{1},{2})",
                        argument1.Build(buildContext, buildArgs),
                        argument2.Build(buildContext, buildArgs),
                        FunctionArgument.Concatenate(otherArguments, buildContext, buildArgs));
                    buildContext.TryTakeException(argument1.Exception, "Sys.Coalesce");
                    buildContext.TryTakeException(argument2.Exception, "Sys.Coalesce");
                    return sql;
                }));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// <para>CONVERT built-in function.</para>
        /// <para>Converts an expression of one data type to another.</para>
        /// </summary>
        /// <param name="argument">Any expression argument.</param>
        /// <param name="dataTypeDef">The target data type definition.</param>
        /// <param name="style">Is an integer expression that specifies how the CONVERT function is to translate expression. If style is NULL, NULL is returned. The range is determined by dataTypeDef.</param>
        public static SysFn Convert(FunctionArgument argument, DataType dataTypeDef, int style = 0)
        {
            var convert = new ConvertChainer(null, argument, dataTypeDef, style);

            return(convert.GetSys());
        }