public override TSqlQuery Compile(ClauseCompilationContext context) { if (Value == null) { if (!NullValueComparisonOperators.Contains(Operation)) { throw new InvalidOperationException($"Invalid operation for null value. Should be one of {string.Join(", ", NullValueComparisonOperators)}"); } return(GetNullValueQuery()); } Dictionary <string, object> parameters = null; string valueString; if (Value is TSqlStatement tsqlStatement) { valueString = tsqlStatement.GetDescription(); } else { string parameterName = SqlBuilderHelper.GetUniqueParameterName(SqlBuilderHelper.ComposeParameterName(Field.TableName, Field.FieldName), context); context.ParameterNames.Add(parameterName); parameters = new Dictionary <string, object> { { parameterName, Value } }; valueString = SqlBuilderHelper.PrepareParameterName(parameterName); } return(new TSqlQuery( $"{Field.GetFullName()} {SqlBuilderHelper.ConvertBinaryOperationToString(Operation)} {valueString}", parameters )); }
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) { string parameterName = SqlBuilderHelper.ComposeParameterName(Field.TableName, Field.FieldName, context); context.ParameterNames.Add(parameterName); Dictionary <string, object> parameters = new Dictionary <string, object> { { parameterName, Value } }; string query = $"{Field.GetFullName()} {TSqlSyntax.In} {SqlBuilderHelper.PrepareParameterName(parameterName)}"; return(new TSqlQuery(query, parameters)); }
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 )); }