Пример #1
0
        public static EngineResult Evaluate(DeleteSpecification delete, IOutputSink sink, Scope scope)
        {
            var tableRef = (NamedTableReference)delete.Target;
            var table    = scope.Env.Tables[tableRef.SchemaObject.BaseIdentifier.Value];
            var rowCount = 0;

            foreach (var row in table.Rows.ToList())
            {
                if (delete.WhereClause == null ||
                    Evaluate(delete.WhereClause.SearchCondition, new RowArgument(row), scope))
                {
                    table.Rows.Remove(row);
                    rowCount++;
                }

                sink.Deleted(row, scope.Env);
            }

            scope.Env.RowCount = rowCount;
            return(new EngineResult(rowCount));
        }
Пример #2
0
        public static void Evaluate(MergeAction action, Table targetTable, Row row, IOutputSink sink, Scope scope)
        {
            Row GetTargetRow() => row.Sources[EquatableArray.Of(scope.ExpandTableName(new[] { targetTable.Name }))];

            switch (action)
            {
            case InsertMergeAction insert:
                Evaluate(targetTable, insert.Columns, insert.Source, new RowArgument(row), sink, scope);
                return;

            case UpdateMergeAction update:
                Evaluate(update.SetClauses, GetTargetRow(), row, sink, scope);
                return;

            case DeleteMergeAction _:
                var r = GetTargetRow();
                sink.Deleted(r, scope.Env);
                targetTable.Rows.Remove(r);
                return;

            default:
                throw FeatureNotSupportedException.Subtype(action);
            }
        }