Exemplo n.º 1
0
    private List <IPlanStep> GetDeleteSteps(DeleteStatement statement)
    {
        var result = new List <IPlanStep>();

        var step = new DeleteStep();

        step.DatabaseName = statement.DatabaseName;
        step.TableName    = statement.Tables.First();

        if (statement.HasWhereClause)
        {
            // need to delete only the rows in the where clause
            step.InputStep = QueryPlanGeneratorUtility.GetMaxStep(_plan.Steps);
            step.Level     = step.InputStep.Level++;
            var rows = step.InputStep.GetResult(_process, statement.DatabaseName).Rows;
            step.DeletedRows = rows;
        }
        else
        {
            // delete everything
            step.ShouldDeleteAllRows = true;
        }

        result.Add(step);

        return(result);
    }
Exemplo n.º 2
0
    public QueryPlan GeneratePlan(UpdateStatement statement)
    {
        var result = new QueryPlan();

        statement.ParseElements();
        // TO DO: We need to extract out from the Select Plan Generator
        // a generic WhereClausePlanGenerator because the behavior should be the same, i.e.
        // generate the plan steps to find the rows that apply to a WHERE clause
        // and then either return those rows or take an action on them (DELETE, or UPDATE)
        result.Steps.AddRange(GetWhereClauseSteps(statement));
        _level = QueryPlanGeneratorUtility.GetMaxLevel(result.Steps);
        result.Steps.AddRange(GetUpdateSteps(statement, result.Steps));
        result.OriginalStatement = statement;
        return(result);
    }
Exemplo n.º 3
0
    // TO DO: We need to figure out how to input the rows we wish to affect
    private List <IPlanStep> GetUpdateSteps(UpdateStatement statement, List <IPlanStep> existingSteps)
    {
        var result = new List <IPlanStep>();

        foreach (var element in statement.Elements)
        {
            var step = new UpdateStep();

            if (statement.HasWhereClause)
            {
                step.InputStep = QueryPlanGeneratorUtility.GetMaxStep(existingSteps);
            }

            step.TableName    = element.TableName;
            step.DatabaseName = element.DatabaseName;
            step.ColumnName   = element.ColumnName;
            step.Value        = element.Value;
            _level++;
            step.Level = _level;
            result.Add(step);
        }

        return(result);
    }