public override TSqlQuery Compile(ClauseCompilationContext context) { Dictionary <string, object> parameters = new Dictionary <string, object>(); string properties = string.Join(TSqlSyntax.FieldsDelimeter, FieldWithValues.Keys); string values = string.Join(TSqlSyntax.FieldsDelimeter, FieldWithValues.Keys.Select(fieldName => { object fieldValue = FieldWithValues[fieldName]; if (fieldValue is TSqlStatement tsqlStatement) { return(tsqlStatement.GetDescription()); } string parameterName = SqlBuilderHelper.ComposeParameterName(TableName, fieldName, context); context.ParameterNames.Add(parameterName); parameters.Add(parameterName, FieldWithValues[fieldName]); return(SqlBuilderHelper.PrepareParameterName(parameterName)); })); StringBuilder sb = new StringBuilder(); sb .AppendLine($"{TSqlSyntax.Insert} {SqlBuilderHelper.PrepareTableName(TableName)} ({properties})") .AppendLine($"{TSqlSyntax.Values} ({values})"); return(new TSqlQuery(sb.ToString(), parameters)); }
public override TSqlQuery Compile(ClauseCompilationContext context) { StringBuilder sb = new StringBuilder(); sb.Append($"{JoinType.GetDescription()} {TSqlSyntax.Join} {SqlBuilderHelper.PrepareTableName(JoinedTable)}"); if (TableHints.HasValue) { string hints = SqlBuilderHelper.GetTableHintString(TableHints.Value); sb.Append(" "); sb.Append($"{TSqlSyntax.With}({hints})"); } sb.Append(" "); sb.Append($"{TSqlSyntax.On} {LeftField.GetFullName()} {SqlBuilderHelper.ConvertBinaryOperationToString(Operation)} {RightField.GetFullName()}"); return(new TSqlQuery(sb.ToString())); }
public override TSqlQuery Compile(ClauseCompilationContext context) { string concatenatedFields = TSqlSyntax.AllFieldsSymbol; if (SelectItems != null & SelectItems.Any()) { concatenatedFields = string.Join( TSqlSyntax.FieldsDelimeter, SelectItems.Select(f => f.Compile()) ); } StringBuilder sb = new StringBuilder(); sb.Append($"{TSqlSyntax.Select}"); if (Distinct) { sb.Append(" "); sb.Append($"{TSqlSyntax.Distinct}"); } if (topCount.HasValue) { sb.Append(" "); sb.Append($"{TSqlSyntax.Top} {topCount}"); } sb.Append(" "); sb.Append($"{concatenatedFields} {TSqlSyntax.From} {SqlBuilderHelper.PrepareTableName(TableName)}"); if (TableHints.HasValue) { string hints = SqlBuilderHelper.GetTableHintString(TableHints.Value); sb.Append(" "); sb.Append($"{TSqlSyntax.With}({hints})"); } return(new TSqlQuery(sb.ToString())); }
public override TSqlQuery Compile(ClauseCompilationContext context) { Dictionary <string, object> parameters = new Dictionary <string, object>(); StringBuilder sb = new StringBuilder(); foreach (UpdateClauseItem item in UpdateItems) { if (sb.Length > 0) { sb.Append(TSqlSyntax.FieldsDelimeter); } string fieldName = SqlBuilderHelper.PrepareFieldName(TableName, item.FieldName); string assignmentOperatorString = SqlBuilderHelper.ConvertAssignmentOperatorToString(item.AssignmentOperator); string valueString; if (item.Value is TSqlStatement tsqlStatement) { valueString = tsqlStatement.GetDescription(); } else { string parameterName = SqlBuilderHelper.ComposeParameterName(TableName, item.FieldName, context); context.ParameterNames.Add(parameterName); parameters.Add(parameterName, item.Value); valueString = SqlBuilderHelper.PrepareParameterName(parameterName); } sb.AppendLine($"{fieldName} {assignmentOperatorString} {valueString}"); } return(new TSqlQuery( $"{TSqlSyntax.Update} {SqlBuilderHelper.PrepareTableName(TableName)} {TSqlSyntax.Set} {sb}", parameters )); }
public override TSqlQuery Compile(ClauseCompilationContext context) { string query = $"{TSqlSyntax.Delete} {TSqlSyntax.From} {SqlBuilderHelper.PrepareTableName(TableName)}"; return(new TSqlQuery(query)); }