public void TestDelete_AliasedTable_WithAs() { Table table = new Table("Table"); DeleteBuilder builder = new DeleteBuilder(table, "t"); Formatter formatter = new Formatter(); string commandText = formatter.GetCommandText(builder, new CommandOptions() { AliasColumnSourcesUsingAs = true }); string expected = "DELETE FROM Table AS t"; Assert.AreEqual(expected, commandText, "The wrong SQL was generated."); }
public void TestDelete_AliasedTable() { Table table = new Table("Table"); DeleteBuilder builder = new DeleteBuilder(table, "t"); Formatter formatter = new Formatter(); string commandText = formatter.GetCommandText(builder); string expected = "DELETE FROM Table t"; Assert.AreEqual(expected, commandText, "The wrong SQL was generated."); }
public void TestDelete_Where() { Table table = new Table("Table"); DeleteBuilder builder = new DeleteBuilder(table); builder.AddWhere(new EqualToFilter(builder.Table.Column("Column"), new NumericLiteral(1))); Formatter formatter = new Formatter(); string commandText = formatter.GetCommandText(builder); string expected = "DELETE FROM Table WHERE Column = 1"; Assert.AreEqual(expected, commandText, "The wrong SQL was generated."); }
/// <summary> /// Generates the text for a Delete builder. /// </summary> /// <param name="item">The Delete builder to generate the text for.</param> protected internal override void VisitDelete(DeleteBuilder item) { forCommandType(CommandType.Delete).visitDelete(item); }
private void visitDelete(DeleteBuilder item) { writer.Write("DELETE "); if (options.VerboseDeleteStatement) { writer.Write("FROM "); } forSourceContext(SourceReferenceType.Declaration).visitAliasedSource(item.Table); if (item.WhereFilterGroup.HasFilters) { writer.Write(" WHERE "); IFilter filterGroup = item.WhereFilterGroup; filterGroup.Accept(forSubCommand().forValueContext(ValueReferenceType.Reference)); } }
/// <summary> /// Visits a Delete builder. /// </summary> /// <param name="item">The item to visit.</param> protected internal virtual void VisitDelete(DeleteBuilder item) { }
private ICommand buildDeleteStatement(MatchResult result) { MatchResult tableResult = result.Matches[SqlGrammar.DeleteStatement.Table]; Table table = buildTable(tableResult); string alias = null; MatchResult aliasExpressionResult = result.Matches[SqlGrammar.DeleteStatement.AliasExpression.Name]; if (aliasExpressionResult.IsMatch) { MatchResult aliasResult = aliasExpressionResult.Matches[SqlGrammar.DeleteStatement.AliasExpression.Alias]; alias = getToken(aliasResult); } DeleteBuilder builder = new DeleteBuilder(table, alias); SourceCollection collection = new SourceCollection(); collection.AddSource(builder.Table.GetSourceName(), builder.Table); scope.Push(collection); MatchResult whereResult = result.Matches[SqlGrammar.DeleteStatement.Where.Name]; if (whereResult.IsMatch) { MatchResult filterListResult = whereResult.Matches[SqlGrammar.DeleteStatement.Where.FilterList]; IFilter innerFilter = buildOrFilter(filterListResult); builder.WhereFilterGroup.AddFilter(innerFilter); builder.WhereFilterGroup.Optimize(); } scope.Pop(); return builder; }
protected override void VisitDelete(DeleteBuilder item) { var visitor = new DeleteRequestBuilderVisitor(Parameters, CrmMetadataProvider, TypeProvider, Settings); IVisitableBuilder visitable = item; visitable.Accept(visitor); SetOperation(visitor.GetCommand()); }