Exemple #1
0
        public RowSetNavigator GetInsertSelectNavigator(Session session)
        {
            SqlType[]       columnTypes     = base.BaseTable.GetColumnTypes();
            int[]           insertColumnMap = base.InsertColumnMap;
            Result          result          = base.queryExpression.GetResult(session, 0);
            RowSetNavigator navigator       = result.InitialiseNavigator();

            SqlType[]             typeArray2 = result.MetaData.ColumnTypes;
            RowSetNavigatorClient client     = new RowSetNavigatorClient(2);

            while (navigator.HasNext())
            {
                object[] newRowData = base.BaseTable.GetNewRowData(session);
                object[] next       = navigator.GetNext();
                for (int i = 0; i < insertColumnMap.Length; i++)
                {
                    int index = insertColumnMap[i];
                    if (index != this.OverrideUserValue)
                    {
                        SqlType type = typeArray2[i];
                        newRowData[index] = columnTypes[index].ConvertToType(session, next[i], type);
                    }
                }
                client.Add(newRowData);
            }
            return(client);
        }
Exemple #2
0
        public RowSetNavigator GetInsertValuesNavigator(Session session)
        {
            SqlType[]             columnTypes = base.BaseTable.GetColumnTypes();
            Expression[]          nodes       = base.InsertExpression.nodes;
            RowSetNavigatorClient client      = new RowSetNavigatorClient(nodes.Length);

            for (int i = 0; i < nodes.Length; i++)
            {
                Expression[] rowArgs = nodes[i].nodes;
                object[]     data    = base.GetInsertData(session, columnTypes, rowArgs);
                client.Add(data);
            }
            return(client);
        }
Exemple #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));
        }