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(); }
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(); }
void ISqlStatementElement.Render(SqlTextWriter writer, SqlBuildArguments args) { args.AssignAlias(this.SubQueryTable); var subquery = new SqlSelectBuilder(this.SubQueryTable); var subQueryColumn = new SqlColumn(this.SubQueryTable, this.SubQueryColumn); subQueryColumn.Aggregate = SqlAggregate.Count; subQueryColumn.Alias = "Cnt"; subquery.Columns.Add(subQueryColumn); foreach (var filter in this.SubQueryFilters) { subquery.Filters.Add(filter); } writer.WriteBeginGroup(); writer.WriteBeginGroup(); subquery.Render(writer, args); writer.WriteEndGroup(); writer.WriteSpace(); writer.WriteOperator(this.CountOperator); writer.WriteSpace(); writer.WriteParameter(args.CreateParameter(this.CountValue, System.Data.DbType.Int32)); writer.WriteEndGroup(); }
void ISqlStatementElement.Render(SqlTextWriter writer, SqlBuildArguments args) { writer.WriteBeginGroup(); writer.WriteColumnName(this.ColumnName, args.TableName(this.Table)); writer.WriteOperator(this.Operator); if (this.EncodeValueAsLiteral) { writer.WriteLiteralValue(this.Value); } else { writer.WriteParameter(args.CreateParameter(this.Value, this.DataType)); } writer.WriteEndGroup(); }
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(); }
/// <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(); }