Esempio n. 1
0
        public StatementDMQL CompileMergeStatement(RangeVariable[] outerRanges)
        {
            int[]             array             = null;
            Expression[]      a                 = null;
            List <Expression> updateExpressions = new List <Expression>();

            Expression[]      emptyArray        = Expression.emptyArray;
            List <Expression> insertExpressions = new List <Expression>();
            Expression        tableExpression   = null;

            base.Read();
            base.ReadThis(0x8b);
            RangeVariable variable   = base.ReadSimpleRangeVariable(0x80);
            Table         rangeTable = variable.RangeTable;

            base.ReadThis(0x130);
            RangeVariable sourceRangeVar = base.ReadTableOrSubquery();

            base.ReadThis(0xc0);
            Expression conditions = base.XreadBooleanValueExpression();

            if (conditions.GetDataType() != SqlType.SqlBoolean)
            {
                throw Error.GetError(0x15c0);
            }
            RangeVariable[]             rangeVarArray      = new RangeVariable[] { sourceRangeVar, variable };
            RangeVariable[]             rangeVariables     = new RangeVariable[] { sourceRangeVar };
            RangeVariable[]             targetRangeVars    = new RangeVariable[] { variable };
            int[]                       columnMap          = rangeTable.GetColumnMap();
            bool[]                      newColumnCheckList = rangeTable.GetNewColumnCheckList();
            OrderedHashSet <Expression> updateTargetSet    = new OrderedHashSet <Expression>();
            OrderedHashSet <string>     insertColumnNames  = new OrderedHashSet <string>();
            LongDeque                   updateColIndexList = new LongDeque();

            this.ReadMergeWhen(updateColIndexList, insertColumnNames, updateTargetSet, insertExpressions, updateExpressions, targetRangeVars, sourceRangeVar);
            if (insertExpressions.Count > 0)
            {
                if (insertColumnNames.Size() != 0)
                {
                    columnMap          = rangeTable.GetColumnIndexes(insertColumnNames);
                    newColumnCheckList = rangeTable.GetColumnCheckList(columnMap);
                }
                tableExpression = insertExpressions[0];
                SetParameterTypes(tableExpression, rangeTable, columnMap);
            }
            if (updateExpressions.Count > 0)
            {
                a = new Expression[updateTargetSet.Size()];
                updateTargetSet.ToArray(a);
                for (int i = 0; i < a.Length; i++)
                {
                    this.ResolveOuterReferencesAndTypes(outerRanges, a[i]);
                }
                emptyArray = updateExpressions.ToArray();
                array      = new int[updateColIndexList.Size()];
                updateColIndexList.ToArray(array);
            }
            if (emptyArray.Length != 0)
            {
                Table baseTable = rangeTable.GetBaseTable();
                if (rangeTable != baseTable)
                {
                    int[] newRow = new int[array.Length];
                    ArrayUtil.ProjectRow(rangeTable.GetBaseTableColumnMap(), array, newRow);
                }
                this.ResolveUpdateExpressions(rangeTable, rangeVariables, array, emptyArray, outerRanges);
            }
            List <Expression> set = conditions.ResolveColumnReferences(rangeVarArray, null);

            ExpressionColumn.CheckColumnsResolved(set);
            conditions.ResolveTypes(base.session, null);
            if (conditions.IsUnresolvedParam())
            {
                conditions.DataType = SqlType.SqlBoolean;
            }
            if (conditions.GetDataType() != SqlType.SqlBoolean)
            {
                throw Error.GetError(0x15c0);
            }
            RangeVariableResolver resolver1 = new RangeVariableResolver(rangeVarArray, conditions, base.compileContext);

            resolver1.ProcessConditions(base.session);
            rangeVarArray = resolver1.GetRangeVariables();
            if (tableExpression != null)
            {
                ExpressionColumn.CheckColumnsResolved(tableExpression.ResolveColumnReferences(rangeVariables, set));
                tableExpression.ResolveTypes(base.session, null);
            }
            StatementDML tdml1 = new StatementDML(base.session, a, rangeVarArray, columnMap, array, newColumnCheckList, conditions, tableExpression, emptyArray, base.compileContext);

            tdml1.CheckAccessRights(base.session);
            return(tdml1);
        }
Esempio n. 2
0
        public StatementDMQL CompileUpdateStatement(RangeVariable[] outerRanges)
        {
            base.Read();
            OrderedHashSet <Expression> targets = new OrderedHashSet <Expression>();
            LongDeque         colIndexList      = new LongDeque();
            List <Expression> expressions       = new List <Expression>();

            RangeVariable[] rangeVars  = new RangeVariable[] { base.ReadSimpleRangeVariable(0x52) };
            Table           rangeTable = rangeVars[0].RangeTable;
            Table           baseTable  = rangeTable.GetBaseTable();

            base.ReadThis(0xfc);
            this.ReadSetClauseList(rangeVars, targets, colIndexList, expressions);
            int[] array = new int[colIndexList.Size()];
            colIndexList.ToArray(array);
            Expression[] a = new Expression[targets.Size()];
            targets.ToArray(a);
            for (int i = 0; i < a.Length; i++)
            {
                this.ResolveOuterReferencesAndTypes(outerRanges, a[i]);
            }
            bool[]       columnCheckList = rangeTable.GetColumnCheckList(array);
            Expression[] colExpressions  = expressions.ToArray();
            Expression   expression      = null;

            if (base.token.TokenType == 0x13a)
            {
                base.Read();
                expression = base.XreadBooleanValueExpression();
                List <Expression> sourceSet = expression.ResolveColumnReferences(outerRanges, null);
                if (outerRanges.Length != 0)
                {
                    sourceSet = Expression.ResolveColumnSet(outerRanges, outerRanges.Length, sourceSet, null);
                }
                ExpressionColumn.CheckColumnsResolved(Expression.ResolveColumnSet(rangeVars, rangeVars.Length, sourceSet, null));
                expression.ResolveTypes(base.session, null);
                if (expression.IsUnresolvedParam())
                {
                    expression.DataType = SqlType.SqlBoolean;
                }
                if (expression.GetDataType() != SqlType.SqlBoolean)
                {
                    throw Error.GetError(0x15c0);
                }
            }
            this.ResolveUpdateExpressions(rangeTable, rangeVars, array, colExpressions, outerRanges);
            if (rangeTable != baseTable)
            {
                QuerySpecification mainSelect = rangeTable.GetQueryExpression().GetMainSelect();
                RangeVariable[]    newRanges  = (RangeVariable[])mainSelect.RangeVariables.Clone();
                newRanges[0] = mainSelect.RangeVariables[0].Duplicate();
                Expression[] list = new Expression[mainSelect.IndexLimitData];
                for (int j = 0; j < mainSelect.IndexLimitData; j++)
                {
                    Expression expression3 = mainSelect.ExprColumns[j].Duplicate();
                    list[j] = expression3;
                    expression3.ReplaceRangeVariables(mainSelect.RangeVariables, newRanges);
                }
                Expression queryCondition = mainSelect.QueryCondition;
                if (queryCondition != null)
                {
                    queryCondition = queryCondition.Duplicate();
                    queryCondition.ReplaceRangeVariables(rangeVars, newRanges);
                }
                if (expression != null)
                {
                    expression = expression.ReplaceColumnReferences(rangeVars[0], list);
                }
                for (int k = 0; k < colExpressions.Length; k++)
                {
                    colExpressions[k] = colExpressions[k].ReplaceColumnReferences(rangeVars[0], list);
                }
                rangeVars  = newRanges;
                expression = ExpressionLogical.AndExpressions(queryCondition, expression);
            }
            if (expression != null)
            {
                rangeVars[0].AddJoinCondition(expression);
                RangeVariableResolver resolver1 = new RangeVariableResolver(rangeVars, null, base.compileContext);
                resolver1.ProcessConditions(base.session);
                rangeVars = resolver1.RangeVariables;
            }
            if ((baseTable != null) && (rangeTable != baseTable))
            {
                int[] newRow = new int[array.Length];
                ArrayUtil.ProjectRow(rangeTable.GetBaseTableColumnMap(), array, newRow);
                array = newRow;
                for (int j = 0; j < array.Length; j++)
                {
                    if (baseTable.ColGenerated[array[j]])
                    {
                        throw Error.GetError(0x1589);
                    }
                }
            }
            StatementDML tdml1 = new StatementDML(base.session, a, rangeTable, rangeVars, array, colExpressions, columnCheckList, base.compileContext);

            tdml1.CheckAccessRights(base.session);
            return(tdml1);
        }
Esempio n. 3
0
        public StatementDMQL CompileDeleteStatement(RangeVariable[] outerRanges)
        {
            Expression expression = null;
            int        num2;
            bool       flag            = false;
            bool       restartIdentity = false;
            int        tokenType       = base.token.TokenType;

            if (tokenType != 0x4e)
            {
                if (tokenType != 0x125)
                {
                    throw base.UnexpectedToken();
                }
                base.Read();
                base.ReadThis(0x114);
                flag = true;
                num2 = 0x451;
            }
            else
            {
                base.Read();
                base.ReadThis(0x72);
                num2 = 0x13;
            }
            RangeVariable[] rangeVars   = new RangeVariable[] { base.ReadSimpleRangeVariable(num2) };
            Table           targetTable = rangeVars[0].GetTable();
            Table           baseTable   = targetTable.GetBaseTable();

            if (flag)
            {
                if (targetTable != baseTable)
                {
                    throw Error.GetError(0x15a9);
                }
                if (targetTable.IsTriggerDeletable())
                {
                    throw Error.GetError(0x15a9);
                }
                switch (base.token.TokenType)
                {
                case 0x178:
                    base.Read();
                    base.ReadThis(0x7f);
                    break;

                case 0x1e3:
                    base.Read();
                    base.ReadThis(0x7f);
                    restartIdentity = true;
                    break;
                }
                if (targetTable.FkMainConstraints.Length != 0)
                {
                    throw Error.GetError(8);
                }
            }
            if (!flag && (base.token.TokenType == 0x13a))
            {
                base.Read();
                expression = base.XreadBooleanValueExpression();
                List <Expression> sourceSet = expression.ResolveColumnReferences(outerRanges, null);
                if (outerRanges.Length != 0)
                {
                    sourceSet = Expression.ResolveColumnSet(outerRanges, outerRanges.Length, sourceSet, null);
                }
                ExpressionColumn.CheckColumnsResolved(Expression.ResolveColumnSet(rangeVars, rangeVars.Length, sourceSet, null));
                expression.ResolveTypes(base.session, null);
                if (expression.IsUnresolvedParam())
                {
                    expression.DataType = SqlType.SqlBoolean;
                }
                if (expression.GetDataType() != SqlType.SqlBoolean)
                {
                    throw Error.GetError(0x15c0);
                }
            }
            if (targetTable != baseTable)
            {
                QuerySpecification mainSelect = targetTable.GetQueryExpression().GetMainSelect();
                RangeVariable[]    newRanges  = (RangeVariable[])mainSelect.RangeVariables.Clone();
                newRanges[0] = mainSelect.RangeVariables[0].Duplicate();
                Expression[] list = new Expression[mainSelect.IndexLimitData];
                for (int i = 0; i < mainSelect.IndexLimitData; i++)
                {
                    Expression expression3 = mainSelect.ExprColumns[i].Duplicate();
                    list[i] = expression3;
                    expression3.ReplaceRangeVariables(mainSelect.RangeVariables, newRanges);
                }
                Expression queryCondition = mainSelect.QueryCondition;
                if (queryCondition != null)
                {
                    queryCondition = queryCondition.Duplicate();
                    queryCondition.ReplaceRangeVariables(rangeVars, newRanges);
                }
                if (expression != null)
                {
                    expression = expression.ReplaceColumnReferences(rangeVars[0], list);
                }
                rangeVars  = newRanges;
                expression = ExpressionLogical.AndExpressions(queryCondition, expression);
            }
            if (expression != null)
            {
                rangeVars[0].AddJoinCondition(expression);
                RangeVariableResolver resolver1 = new RangeVariableResolver(rangeVars, null, base.compileContext);
                resolver1.ProcessConditions(base.session);
                rangeVars = resolver1.RangeVariables;
            }
            StatementDML tdml1 = new StatementDML(base.session, targetTable, rangeVars, base.compileContext, restartIdentity, num2);

            tdml1.CheckAccessRights(base.session);
            return(tdml1);
        }