示例#1
0
        private static void BeginEmbeddedTransactionWrapper(Designer root, StringBuilder sql,
                                                            string trancountVar, string transaveVar)
        {
            var isolationLevel = root.EmbeddedTransactionIsolationLevel;

            if (isolationLevel != Designer.IsolationLevel.Default)
            {
                sql.NewLine(Text.SetTransactionIsolationLevel).S().Append(isolationLevel.ToSql()).Terminate();
            }

            sql
            .NewLine(String.Format("DECLARE {0} AS [int];", trancountVar))
            .Append(String.Format("SELECT {0} = @@TRANCOUNT;", trancountVar))
            .Append(String.Format("IF {0} > 0 SAVE TRANSACTION {1};", trancountVar, transaveVar))
            .Append("ELSE BEGIN TRANSACTION;")
            .Append("BEGIN TRY;")
            .NewLine();
        }
示例#2
0
 internal static SelectChainer SelectCountBig(this ISelect prev)
 {
     return(new SelectChainer((Chainer)prev, new Column[] { Designer.CountBig() }, false));
 }
示例#3
0
 /// <summary>
 /// Retrieves the number of rows returned by the query.
 /// </summary>
 /// <param name="prev">A predecessor object.</param>
 public static SelectChainer SelectCount(this ISemqToSql prev)
 {
     prev.CheckNullAndThrow(Text.Free.Sentence, Text.Method.SelectCount);
     return(new SelectChainer((ISemantic)prev, new Column[] { Designer.Count().As(Text.Count) }, false));
 }
示例#4
0
        // Builds argument with critical check if the argument is bound to a certain param.
        internal void BuildArgument(Designer root, string paramName)
        {
            // check if a param with the given param name exists
            Variable param = root.TryGetVariable(paramName, out chainException, Variable.SearchType.Param);

            if (chainException != null)
            {
                chainException.Method = Text.Method.Pass;
                return;
            }

            // check: argument is null/NULL
            if (QueryTalk.Value.IsNull(Value))
            {
                if (IsPassedVariable || !param.ParamNullCheck(out chainException))
                {
                    chainException.Method    = Text.Method.Pass;
                    chainException.Arguments = String.Format("param = {0}", paramName);
                    return;
                }
            }

            // store param data
            ParamName       = paramName;
            _dt             = param.DT;
            DataType        = param.DataType;
            IsParamOutput   = param.IsOutput;
            IsParameterized = param.IsParameterized;

            // clear parameterized value on param
            if (IsParameterized)
            {
                param.ClearParameterizedValue();
            }

            // udt: store compiled SQL
            if (param.DT.IsNameType())
            {
                NameTypeSql = param.NameType.Sql;
            }

            // table variable/temp table/bulk table: cannot be passed as variable
            if (DT.IsVTB())
            {
                // bulk table
                if (DT == Wall.DT.BulkTable)
                {
                    if (Value.GetType() != typeof(DataTable))
                    {
                        chainException = new QueryTalkException("Param.BuildArgument", QueryTalkExceptionType.InvalidTableArgument,
                                                                String.Format(
                                                                    "bulk table = {0}{1}   argument type = {2}{3}   required type = {4}",
                                                                    ParamName, Environment.NewLine, ArgType, Environment.NewLine, typeof(DataTable)),
                                                                Text.Method.Pass);
                        return;
                    }
                    else
                    {
                        return;
                    }
                }

                // table variable/temp table
                if (Value.GetType() != typeof(View))
                {
                    chainException = new QueryTalkException("Param.BuildArgument", QueryTalkExceptionType.InvalidTableArgument,
                                                            String.Format(
                                                                "param = {0}{1}   argument type = {2}{3}   required type = {4}",
                                                                ParamName, Environment.NewLine, ArgType, Environment.NewLine, typeof(View)),
                                                            Text.Method.Pass);
                    return;
                }
            }

            // finish if argument has been passed as variable
            if (IsPassedVariable)
            {
                Sql = Original.ToString();
                return;
            }

            // argument type check
            if (!CheckType(param, Value, out chainException))
            {
                chainException.Method = Text.Method.Pass;
                return;
            }

            // Here the check has passed. Argument is properly bound to its param.
            // Now build the SQL output.

            // value
            if (DT.IsDataType() || DT.IsNameType())
            {
                if (ArgType == typeof(View))
                {
                    Sql = ((View)Original).Sql;
                }
                else if (ArgType == typeof(DataTable))
                {
                    Sql = null;
                }
                else if (ArgType == typeof(OutputVar))
                {
                    Sql = ((OutputVar)Original).Value;
                }
                // common type
                else
                {
                    Sql = Mapping.BuildUnchecked(Value, out chainException);
                }
            }
            // inline
            else
            {
                // table
                if (DT == DT.InTable)
                {
                    if (IsPassedVariable)
                    {
                        Sql = (string)Value;
                    }
                    // Identifier (build by Build method)
                    else
                    {
                    }
                }
                // sql
                else if (DT == DT.InSql)
                {
                    if (IsPassedVariable)
                    {
                        Sql = (string)Value;
                    }
                    else
                    {
                        Sql = _string;
                    }
                }
                // other inline types must be built by the Build method
                else
                {
                }
            }
        }
示例#5
0
 /// <summary>
 /// <para>Retrieves the number of rows returned by the query.</para>
 /// </summary>
 /// <param name="prev">A predecessor object.</param>
 public static SelectChainer SelectCount(this ISelect prev)
 {
     return(new SelectChainer((Chainer)prev, new Column[] { Designer.Count().As(Text.Count) }, false));
 }
示例#6
0
 /// <summary>
 /// Converts a value of one data type to another.
 /// </summary>
 /// <param name="value">A Value object.</param>
 /// <param name="dataType">The target data type definition.</param>
 public static SysFn CastAs(this Value value, Wall.DataType dataType)
 {
     return(Designer.Cast(value, dataType));
 }
示例#7
0
 /// <summary>
 /// Converts a value of one data type to another.
 /// </summary>
 /// <param name="value">The value to convert.</param>
 /// <param name="dataType">The target data type definition.</param>
 public static SysFn CastAs(this System.TimeSpan value, Wall.DataType dataType)
 {
     return(Designer.Cast(value, dataType));
 }