示例#1
0
 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.");
 }
示例#2
0
 private void buildColumnsList(MatchResult result, InsertBuilder builder)
 {
     MatchResult multiple = result.Matches[SqlGrammar.ColumnList.Multiple.Name];
     if (multiple.IsMatch)
     {
         MatchResult first = multiple.Matches[SqlGrammar.ColumnList.Multiple.First];
         Column column = buildColumn(first);
         builder.AddColumn(column);
         MatchResult remaining = multiple.Matches[SqlGrammar.ColumnList.Multiple.Remaining];
         buildColumnsList(remaining, builder);
         return;
     }
     MatchResult single = result.Matches[SqlGrammar.ColumnList.Single];
     if (single.IsMatch)
     {
         Column column = buildColumn(single);
         builder.AddColumn(column);
         return;
     }
     throw new InvalidOperationException();
 }
示例#3
0
 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.");
 }