Beispiel #1
0
        void ISqlStatementElement.Render(SqlTextWriter writer, SqlBuildArguments args)
        {
            writer.WriteBeginGroup();

            writer.WriteColumnName(this.ColumnName, args.TableName(this.Table));
            writer.WriteSpace();

            if (this.Condition == SubQueryMode.NotInList)
            {
                writer.Write(SqlConstants.NOT);
                writer.WriteSpace();
            }

            writer.Write(SqlConstants.IN);

            writer.WriteSpace();

            args.AssignAlias(this.SubQueryTable);

            var builder        = new SqlSelectBuilder(this.SubQueryTable);
            var subQueryColumn = new SqlColumn(this.SubQueryTable, this.SubQueryColumn);

            builder.Columns.Add(subQueryColumn);

            foreach (var filter in this.SubQueryFilters)
            {
                builder.Filters.Add(filter);
            }

            writer.WriteBeginGroup();
            builder.Render(writer, args);
            writer.WriteEndGroup();

            writer.WriteEndGroup();
        }
Beispiel #2
0
 protected override void RenderInternal(SqlTextWriter writer, SqlBuildArguments args)
 {
     writer.WriteBeginGroup();
     writer.Write(this.CommandText.TrimEnd(new char[] { '\r', '\n', ';', ' ', '\t' }));
     writer.WriteEndGroup();
     writer.WriteSpace();
     writer.Write(SqlConstants.AS);
     writer.WriteSpace();
     writer.Write(SqlDataColumn.Format(args.TableName(this)));
 }
Beispiel #3
0
        void ISqlStatementElement.Render(SqlTextWriter writer, SqlBuildArguments args)
        {
            string[] resolvedArguments = new string[0];

            if (this.Arguments != null)
            {
                resolvedArguments = this.Arguments.Select(arg =>
                {
                    if (arg is ISqlTable table)
                    {
                        return(writer.FormatQualifiedIdentifierName(args.TableName(table)));
                    }
                    else if (arg is System.Data.Common.DbParameter dbParam)
                    {
                        return(string.Concat("@", dbParam.ParameterName));
                    }
                    else if (arg is DbParameterValue paramValue)
                    {
                        return(string.Concat("@", args.CreateParameter(paramValue.ParameterName, paramValue.DbType, paramValue.Size)));
                    }
                    else if (arg is string)
                    {
                        return(string.Concat("@", args.CreateParameter(arg.ToString(), System.Data.DbType.String)));
                    }
                    else
                    {
                        return(string.Concat("@", args.CreateParameter(arg, System.Data.DbType.String)));
                    }
                }).ToArray();
            }

            writer.WriteBeginGroup();
            writer.Write(string.Format(this.SqlText, resolvedArguments));
            writer.WriteEndGroup();
        }
 /// <summary>
 /// Renders the entire SQL statement.
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="args"></param>
 protected override void Render(SqlTextWriter writer, SqlBuildArguments args)
 {
     this.RenderValueExpression(writer, args);
     writer.WriteSpace();
     writer.Write(SqlConstants.AS);
     writer.WriteSpace();
     writer.WriteColumnName(this.Alias);
 }
 public void Render(SqlTextWriter writer, SqlBuildArguments args)
 {
     writer.WriteBeginGroup();
     writer.WriteColumnName(this.ColumnName, args.TableName(this.Table));
     writer.WriteOperator(this.Operator);
     writer.Write(this.ParameterName);
     writer.WriteEndGroup();
 }
Beispiel #6
0
 protected override void RenderInternal(SqlTextWriter writer, SqlBuildArguments args)
 {
     //TODO: Make this impl agnostic
     writer.WriteBeginGroup();
     writer.WriteColumnName(this.ColumnName, args.TableName(this.Table));
     writer.Write((this.IsNull) ? " IS NULL" : " IS NOT NULL");
     writer.WriteEndGroup();
 }
Beispiel #7
0
 void ISqlStatementElement.Render(SqlTextWriter writer, SqlBuildArguments args)
 {
     writer.WriteBeginGroup();
     writer.Write("EXISTS ");
     writer.WriteBeginGroup();
     this.Statement.Render(writer, args);
     writer.WriteEndGroup();
     writer.WriteEndGroup();
 }
Beispiel #8
0
 public void Render(SqlTextWriter writer, SqlBuildArguments args)
 {
     writer.WriteLiteralValue(this.Value);
     if (this.Alias != null)
     {
         writer.WriteSpace();
         writer.Write(SqlConstants.AS);
         writer.WriteSpace();
         writer.WriteColumnName(this.Alias);
     }
 }
Beispiel #9
0
        /// <summary>
        /// Renders the raw value to the writer with its alias, if it exists
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="args"></param>
        public void Render(SqlTextWriter writer, SqlBuildArguments args)
        {
            RenderValueExpression(writer, args);

            if (this.Alias != null)
            {
                writer.WriteSpace();
                writer.Write(SqlConstants.AS);
                writer.WriteSpace();
                writer.WriteColumnName(this.Alias);
            }
        }
Beispiel #10
0
 void ISqlStatementElement.Render(SqlTextWriter writer, SqlBuildArguments args)
 {
     writer.WriteBeginGroup();
     this.WriteColumnName(writer, args);
     writer.WriteOperator(SqlOperator.GreaterThanOrEqual);
     writer.WriteParameter(args.CreateParameter(this.GetBeginDate(), System.Data.DbType.DateTime));
     writer.WriteSpace();
     writer.Write(SqlConstants.AND);
     writer.WriteSpace();
     this.WriteColumnName(writer, args);
     writer.WriteOperator(SqlOperator.LessThanOrEqual);
     writer.WriteParameter(args.CreateParameter(this.GetEndDate(), System.Data.DbType.DateTime));
     writer.WriteEndGroup();
 }
Beispiel #11
0
        /// <summary>
        /// Renders the query.
        /// </summary>
        /// <param name="supressEndStatement">True if you want to supress statement terminating characters (semicolon)</param>
        /// <returns></returns>
        public SqlStatement Render(bool supressEndStatement)
        {
            var writer = new SqlTextWriter()
            {
                Format = this.GenerateFormattedSql
            };
            var args = new SqlBuildArguments();

            this.CompileInternal(args);

            if (this.Prefix != null)
            {
                writer.Write(this.Prefix);
                if (!supressEndStatement)
                {
                    writer.WriteEndStatement();
                }
            }

            this.RenderInternal(writer, args);

            if (!supressEndStatement)
            {
                writer.WriteEndStatement();
            }

            if (this.Suffix != null)
            {
                writer.Write(this.Suffix);
                if (!supressEndStatement)
                {
                    writer.WriteEndStatement();
                }
            }

            return(new SqlStatement(writer.ToString(), args.Parameters));
        }
        /// <summary>
        /// Renders the portion of the SQL statement that will be used as the value.
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="args"></param>
        protected override void RenderValueExpression(SqlTextWriter writer, SqlBuildArguments args)
        {
            var expr = this.Expression;

            expr = expr.Replace("{0}", args.TableName(this.Table));
            if (_referenceTables != null && _referenceTables.Count > 0)
            {
                for (var i = 0; i < _referenceTables.Count; i++)
                {
                    expr = expr.Replace(string.Concat("{", i + 1, "}"), args.TableName(_referenceTables[i]));
                }
            }
            writer.WriteBeginGroup();
            writer.Write(expr);
            writer.WriteEndGroup();
        }
Beispiel #13
0
        protected override void RenderInternal(SqlTextWriter writer, SqlBuildArguments args)
        {
            string s = this.Value;

            if (s == null)
            {
                s = string.Empty;
            }

            writer.WriteBeginGroup();
            writer.WriteColumnName(this.ColumnName, args.TableName(this.Table));
            writer.WriteSpace();
            writer.Write(SqlConstants.LIKE);
            writer.WriteSpace();
            writer.WriteParameter(args.CreateParameter(SqlStringMatchFilter.DecorateValue(this.Value, this.Operator), this.DataType));
            writer.WriteEndGroup();
        }
Beispiel #14
0
        /// <summary>
        /// Writes the filter to the specified <see cref="SqlTextWriter"/> and adds any parameters to the specified <see cref="SqlBuildArguments"/>.
        /// </summary>
        /// <param name="writer">The instance of <see cref="SqlTextWriter"/> to write the T-SQL statement to.</param>
        /// <param name="args">An instance of <see cref="SqlBuildArguments"/> to use for parameters.</param>
        protected override void RenderInternal(SqlTextWriter writer, SqlBuildArguments args)
        {
            //TODO: make this impl agnostic
            bool first = true;

            if (this.Values == null)
            {
                throw new InvalidOperationException(string.Format(ErrorMessage.SqlListFilter_CollectionIsEmpty, this.ColumnName));
            }

            writer.WriteBeginGroup();
            writer.WriteColumnName(this.ColumnName, args.TableName(this.Table));
            writer.WriteSpace();

            if (this.NotInList)
            {
                writer.Write(SqlConstants.NOT);
                writer.WriteSpace();
            }
            writer.Write(SqlConstants.IN);
            writer.WriteSpace();

            writer.WriteBeginGroup();
            foreach (var v in this.Values)
            {
                if (!first)
                {
                    writer.Write(",");
                }
                else
                {
                    first = false;
                }

                switch (this.DataType)
                {
                case System.Data.DbType.String:
                case System.Data.DbType.StringFixedLength:
                case System.Data.DbType.AnsiString:
                case System.Data.DbType.AnsiStringFixedLength:
                case System.Data.DbType.Object:
                    writer.WriteParameter(args.CreateParameter(v.ToString(), this.DataType, this.Size)); break;

                case System.Data.DbType.Boolean:
                    writer.Write(Convert.ToBoolean(v) ? 1 : 0); break;

                case System.Data.DbType.Int16:
                case System.Data.DbType.Int32:
                case System.Data.DbType.Int64:
                    if (this.UseLiteralNumbers)
                    {
                        writer.Write(Convert.ToInt64(v).ToString());
                    }
                    else
                    {
                        writer.WriteParameter(args.CreateParameter(v, this.DataType, this.Size));
                    }
                    break;

                default:
                    writer.WriteParameter(args.CreateParameter(v, this.DataType, this.Size)); break;
                }
            }

            if (first)
            {
                throw new InvalidOperationException(string.Format(ErrorMessage.SqlListFilter_CollectionIsEmpty, this.ColumnName));
            }

            writer.WriteEndGroup();
            writer.WriteEndGroup();
        }