Ejemplo n.º 1
0
        public Result ExecuteUpdateStatement(Session session)
        {
            Expression[] updateExpressions      = base.UpdateExpressions;
            RowSetNavigatorDataChange navigator = new RowSetNavigatorDataChange();

            SqlType[]      columnTypes = base.BaseTable.GetColumnTypes();
            IRangeIterator iterator    = RangeVariable.GetIterator(session, base.TargetRangeVariables);

            while (iterator.Next())
            {
                session.sessionData.StartRowProcessing();
                Row      currentRow = iterator.GetCurrentRow();
                object[] rowData    = currentRow.RowData;
                object[] data       = GetUpdatedData(session, this._targets, base.BaseTable, base.UpdateColumnMap, updateExpressions, columnTypes, rowData);
                if (this.UpdatableTableCheck != null)
                {
                    iterator.SetCurrent(data);
                    if (!this.UpdatableTableCheck.TestCondition(session))
                    {
                        iterator.Release();
                        throw Error.GetError(0x1644);
                    }
                }
                navigator.AddRow(session, currentRow, data, columnTypes, base.UpdateColumnMap);
            }
            iterator.Release();
            navigator.BeforeFirst();
            int count = this.Update(session, base.BaseTable, navigator);

            switch (count)
            {
            case 1:
                return(Result.UpdateOneResult);

            case 0:
                return(Result.UpdateZeroResult);
            }
            return(new Result(1, count));
        }
Ejemplo n.º 2
0
        public Result ExecuteDeleteStatement(Session session)
        {
            IRangeIterator            iterator  = RangeVariable.GetIterator(session, base.TargetRangeVariables);
            RowSetNavigatorDataChange navigator = new RowSetNavigatorDataChange();

            while (iterator.Next())
            {
                Row currentRow = iterator.GetCurrentRow();
                navigator.AddRow(currentRow);
            }
            iterator.Release();
            if (navigator.GetSize() <= 0)
            {
                return(Result.UpdateZeroResult);
            }
            int count = Delete(session, base.BaseTable, navigator);

            if (count == 1)
            {
                return(Result.UpdateOneResult);
            }
            return(new Result(1, count));
        }
Ejemplo n.º 3
0
        public Result ExecuteMergeStatement(Session session)
        {
            SqlType[]       columnTypes        = base.BaseTable.GetColumnTypes();
            Result          result             = null;
            RowSetNavigator generatedNavigator = null;

            if (base.GeneratedIndexes != null)
            {
                result             = Result.NewUpdateCountResult(base.generatedResultMetaData, 0);
                generatedNavigator = result.GetChainedResult().GetNavigator();
            }
            int count = 0;
            RowSetNavigatorClient     newData   = new RowSetNavigatorClient(8);
            RowSetNavigatorDataChange navigator = new RowSetNavigatorDataChange();

            RangeVariable[]  targetRangeVariables = base.TargetRangeVariables;
            IRangeIterator[] iteratorArray        = new IRangeIterator[targetRangeVariables.Length];
            for (int i = 0; i < targetRangeVariables.Length; i++)
            {
                iteratorArray[i] = targetRangeVariables[i].GetIterator(session);
            }
            int index = 0;

            while (index >= 0)
            {
                IRangeIterator iterator = iteratorArray[index];
                bool           flag     = iterator.IsBeforeFirst();
                if (iterator.Next())
                {
                    if (index < (targetRangeVariables.Length - 1))
                    {
                        index++;
                        continue;
                    }
                    if (base.UpdateExpressions.Length == 0)
                    {
                        continue;
                    }
                    Row      currentRow = iterator.GetCurrentRow();
                    object[] data       = GetUpdatedData(session, this._targets, base.BaseTable, base.UpdateColumnMap, base.UpdateExpressions, columnTypes, currentRow.RowData);
                    try
                    {
                        navigator.AddRow(session, currentRow, data, columnTypes, base.UpdateColumnMap);
                        continue;
                    }
                    catch (CoreException)
                    {
                        for (int k = 0; k < targetRangeVariables.Length; k++)
                        {
                            iteratorArray[k].Reset();
                        }
                        throw Error.GetError(0xc81);
                    }
                }
                if (((index == 1) & flag) && (base.InsertExpression != null))
                {
                    object[] data = this.GetInsertData(session, columnTypes, base.InsertExpression.nodes[0].nodes);
                    if (data != null)
                    {
                        newData.Add(data);
                    }
                }
                iterator.Reset();
                index--;
            }
            for (int j = 0; j < targetRangeVariables.Length; j++)
            {
                iteratorArray[j].Reset();
            }
            if (base.UpdateExpressions.Length != 0)
            {
                count = this.Update(session, base.BaseTable, navigator);
            }
            if (newData.GetSize() > 0)
            {
                this.InsertRowSet(session, generatedNavigator, newData);
                count += newData.GetSize();
            }
            if ((base.InsertExpression != null) && (base.BaseTable.TriggerLists[0].Length != 0))
            {
                base.BaseTable.FireTriggers(session, 0, newData);
            }
            if (result != null)
            {
                result.SetUpdateCount(count);
                return(result);
            }
            if (count == 1)
            {
                return(Result.UpdateOneResult);
            }
            return(new Result(1, count));
        }