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."); }
/// <summary> /// Initializes a new instance of a DeleteBuilder. /// </summary> /// <param name="table">The table being deleted from.</param> /// <param name="alias">The alias to use to refer to the table.</param> public DeleteBuilder(Table table, string alias = null) { if (table == null) { throw new ArgumentNullException("table"); } _table = new AliasedSource(table, alias); _where = new FilterGroup(); }
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 TestInsert_AliasedTable() { Table table = new Table("Table"); ValueList values = new ValueList(); InsertBuilder builder = new InsertBuilder(table, values, "t"); Formatter formatter = new Formatter(); string commandText = formatter.GetCommandText(builder); string expected = "INSERT INTO Table t VALUES()"; 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> /// Initializes a new instance of a InsertBuilder. /// </summary> /// <param name="table">The table being inserted into.</param> /// <param name="values">The values to insert into the table.</param> /// <param name="alias">The alias to use to refer to the table.</param> public InsertBuilder(Table table, IValueProvider values, string alias = null) { if (table == null) { throw new ArgumentNullException("table"); } if (values == null) { throw new ArgumentNullException("values"); } _table = new AliasedSource(table, alias); _columns = new List<Column>(); _values = values; }
private Table buildTable(MatchResult tableResult) { List<string> parts = new List<string>(); buildMultipartIdentifier(tableResult, parts); Namespace qualifier = getNamespace(parts.Take(parts.Count - 1)); string tableName = parts[parts.Count - 1]; Table table = new Table(qualifier, tableName); return table; }
public void TestInsert_AliasedTable_WithAsKeyword() { Table table = new Table("Table"); ValueList values = new ValueList(); InsertBuilder builder = new InsertBuilder(table, values, "t"); Formatter formatter = new Formatter(); string commandText = formatter.GetCommandText(builder, new CommandOptions() { AliasColumnSourcesUsingAs = true }); string expected = "INSERT INTO Table AS t VALUES()"; Assert.AreEqual(expected, commandText, "The wrong SQL was generated."); }
public void TestInsert_SelectAsSource() { Table table = new Table("Table"); SelectBuilder select = new SelectBuilder(); InsertBuilder builder = new InsertBuilder(table, select); builder.AddColumn(builder.Table.Column("Column")); select.AddProjection(new NumericLiteral(1)); Formatter formatter = new Formatter(); string commandText = formatter.GetCommandText(builder, new CommandOptions() { AliasColumnSourcesUsingAs = true }); string expected = "INSERT INTO Table (Column) (SELECT 1)"; Assert.AreEqual(expected, commandText, "The wrong SQL was generated."); }
public void TestUpdate_Where() { Table table = new Table("Table"); UpdateBuilder builder = new UpdateBuilder(table); builder.AddSetter(new Setter(builder.Table.Column("Column"), new NumericLiteral(1))); builder.AddWhere(new EqualToFilter(builder.Table.Column("Column"), new NumericLiteral(2))); Formatter formatter = new Formatter(); string commandText = formatter.GetCommandText(builder); string expected = "UPDATE Table SET Column = 1 WHERE Column = 2"; Assert.AreEqual(expected, commandText, "The wrong SQL was generated."); }
public void TestUpdate_MultipleSetters() { Table table = new Table("Table"); UpdateBuilder builder = new UpdateBuilder(table); builder.AddSetter(new Setter(builder.Table.Column("Column1"), new NumericLiteral(1))); builder.AddSetter(new Setter(builder.Table.Column("Column2"), new StringLiteral("Hello"))); Formatter formatter = new Formatter(); string commandText = formatter.GetCommandText(builder); string expected = "UPDATE Table SET Column1 = 1, Column2 = 'Hello'"; Assert.AreEqual(expected, commandText, "The wrong SQL was generated."); }
public void TestUpdate_AliasedTable_WithAs() { Table table = new Table("Table"); UpdateBuilder builder = new UpdateBuilder(table, "t"); builder.AddSetter(new Setter(builder.Table.Column("Column1"), new NumericLiteral(1))); builder.AddSetter(new Setter(builder.Table.Column("Column2"), new StringLiteral("Hello"))); Formatter formatter = new Formatter(); string commandText = formatter.GetCommandText(builder, new CommandOptions() { AliasColumnSourcesUsingAs = true }); string expected = "UPDATE Table AS t SET Column1 = 1, Column2 = 'Hello'"; Assert.AreEqual(expected, commandText, "The wrong SQL was generated."); }
public void TestInsert_MultipleColumns() { Table table = new Table("Table"); ValueList values = new ValueList(); InsertBuilder builder = new InsertBuilder(table, values); builder.AddColumn(builder.Table.Column("Column1")); builder.AddColumn(builder.Table.Column("Column2")); values.AddValue(new NumericLiteral(1)); values.AddValue(new NullLiteral()); Formatter formatter = new Formatter(); string commandText = formatter.GetCommandText(builder, new CommandOptions() { AliasColumnSourcesUsingAs = true }); string expected = "INSERT INTO Table (Column1, Column2) VALUES(1, NULL)"; Assert.AreEqual(expected, commandText, "The wrong SQL was generated."); }
protected override void VisitTable(Table item) { if (_DetectingMetadataQuery) { switch (item.Name.ToLower()) { case "entitymetadata": case "attributemetadata": case "onetomanyrelationshipmetadata": case "manytomanyrelationshipmetadata": IsMetadataQuery = true; // _IsMetadataQuery = true; break; } } }
/// <summary> /// Adds the given table to the FROM clause. /// </summary> /// <param name="table">The table to add.</param> /// <param name="alias">The optional alias to give the table within the SELECT statement.</param> /// <returns>An object to support aliasing the table and defining columns.</returns> public AliasedSource AddTable(Table table, string alias = null) { if (table == null) { throw new ArgumentNullException("table"); } AliasedSource source = new AliasedSource(table, alias); sources.AddSource(source.GetSourceName(), source); _from.Add(source); return source; }
/// <summary> /// Generates the text for a Table builder. /// </summary> /// <param name="item">The Table builder to generate the text for.</param> protected internal override void VisitTable(Table item) { visitMultipartIdentifier(item.Qualifier, item.Name); }
/// <summary> /// Visits a Table builder. /// </summary> /// <param name="item">The item to visit.</param> protected internal virtual void VisitTable(Table item) { }