public static EngineResult Evaluate( Table table, IList <ColumnReferenceExpression> cols, ValuesInsertSource values, IArgument arg, IOutputSink sink, Scope scope) { foreach (var valuesExpr in values.RowValues) { var row = table.NewRow(scope.Env); for (var i = 0; i < cols.Count; ++i) { // TODO: take the last instead of the first? need more robust handling of multi-part names here var name = cols[i].MultiPartIdentifier.Identifiers[0].Value; row.SetValue(name, Evaluate(valuesExpr.ColumnValues[i], arg, scope)); } sink.Inserted(row, scope.Env); } scope.Env.RowCount = values.RowValues.Count; return(new EngineResult(values.RowValues.Count)); }
public static EngineResult Evaluate(InsertSpecification insert, IOutputSink sink, Scope scope) { var table = scope.Env.GetTable((NamedTableReference)insert.Target); return(insert.InsertSource switch { ValuesInsertSource values => Evaluate(table, insert.Columns, values, NullArgument.It, sink, scope), SelectInsertSource select => Evaluate(table, insert.Columns, Evaluate(@select.Select, scope).ResultSet, sink, scope), _ => throw FeatureNotSupportedException.Subtype(insert.InsertSource) });
public override void ExplicitVisit(ValuesInsertSource node) { if (node.IsDefaultValues) { throw new NotImplementedException(); } _buffer.Append("values"); _buffer.AppendLine(); for (int index = 0, count = node.RowValues.Count - 1; index <= count; ++index) { RowValue rowValue = node.RowValues[index]; rowValue.Accept(this); if (index < count) { _buffer.Append(","); _buffer.AppendLine(); } } _buffer.Append(";"); _buffer.AppendLine(); }
/// <summary> /// Helper method that creates an INSERT statement to track a batch being completed /// </summary> /// <param name="batchId"></param> /// <param name="batchDescription"></param> /// <returns></returns> private static InsertStatement CreateBatchCompleteInsert(int batchId, string batchDescription) { InsertStatement insert = new InsertStatement(); NamedTableReference batchesCompleted = new NamedTableReference(); insert.InsertSpecification = new InsertSpecification(); insert.InsertSpecification.Target = batchesCompleted; batchesCompleted.SchemaObject = CreateCompletedBatchesName(); // Build the columns inserted into ColumnReferenceExpression batchIdColumn = new ColumnReferenceExpression(); batchIdColumn.MultiPartIdentifier = new MultiPartIdentifier(); batchIdColumn.MultiPartIdentifier.Identifiers.Add(CreateIdentifier(BatchIdColumnName, QuoteType.NotQuoted)); ColumnReferenceExpression descriptionColumn = new ColumnReferenceExpression(); descriptionColumn.MultiPartIdentifier = new MultiPartIdentifier(); descriptionColumn.MultiPartIdentifier.Identifiers.Add(CreateIdentifier(DescriptionColumnName, QuoteType.NotQuoted)); insert.InsertSpecification.Columns.Add(batchIdColumn); insert.InsertSpecification.Columns.Add(descriptionColumn); // Build the values inserted ValuesInsertSource valueSource = new ValuesInsertSource(); insert.InsertSpecification.InsertSource = valueSource; RowValue values = new RowValue(); values.ColumnValues.Add(new IntegerLiteral { Value = batchId.ToString() }); values.ColumnValues.Add(new StringLiteral { Value = batchDescription }); valueSource.RowValues.Add(values); return(insert); }
protected override object InternalVisit(ValuesInsertSource node) { return(node.RowValues .Select(rv => Visit <object[]>(rv)) .ToArray()); }
public override void Visit(ValuesInsertSource node) { this.action(node); }
public override void ExplicitVisit(ValuesInsertSource fragment) { _fragments.Add(fragment); }