public void SetRangeIterator(IRangeIterator iterator) { int rangePosition = iterator.GetRangePosition(); if (rangePosition >= this.RangeIterators.Length) { this.RangeIterators = ArrayUtil.ResizeArray <IRangeIterator>(this.RangeIterators, rangePosition + 1); } this.RangeIterators[iterator.GetRangePosition()] = iterator; }
public RangeVariable.RangeIteratorBase GetCheckIterator(RangeVariable rangeVariable) { IRangeIterator iterator = this.RangeIterators[1]; if (iterator == null) { iterator = rangeVariable.GetIterator(this.session); this.RangeIterators[1] = iterator; } return((RangeVariable.RangeIteratorBase)iterator); }
public void InsertRowSet(Session session, RowSetNavigator generatedNavigator, RowSetNavigator newData) { IPersistentStore rowStore = base.BaseTable.GetRowStore(session); IRangeIterator iterator = null; if (this.UpdatableTableCheck != null) { iterator = this._checkRangeVariable.GetIterator(session); } newData.BeforeFirst(); if (base.BaseTable.TriggerLists[6].Length != 0) { while (newData.HasNext()) { object[] next = newData.GetNext(); base.BaseTable.FireTriggers(session, 6, null, next, null); } newData.BeforeFirst(); } while (newData.HasNext()) { object[] next = newData.GetNext(); base.BaseTable.InsertSingleRow(session, rowStore, next, null); if (iterator != null) { iterator.SetCurrent(next); if (!this.UpdatableTableCheck.TestCondition(session)) { throw Error.GetError(0x1644); } } if (generatedNavigator != null) { object[] generatedColumns = base.GetGeneratedColumns(next); generatedNavigator.Add(generatedColumns); } } newData.BeforeFirst(); while (newData.HasNext()) { object[] next = newData.GetNext(); PerformIntegrityChecks(session, base.BaseTable, null, next, null); } newData.BeforeFirst(); if (base.BaseTable.TriggerLists[3].Length != 0) { while (newData.HasNext()) { object[] next = newData.GetNext(); base.BaseTable.FireTriggers(session, 3, null, next, null); } newData.BeforeFirst(); } }
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)); }
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)); }
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)); }