private bool SetOrConditions(RangeVariable.RangeVariableConditions conditions, ExpressionLogical orExpression, int rangeVarIndex) { List <Expression> list = new List <Expression>(); DecomposeOrConditions(orExpression, list); RangeVariable.RangeVariableConditions[] array = new RangeVariable.RangeVariableConditions[list.Count]; for (int i = 0; i < list.Count; i++) { List <Expression> list2 = new List <Expression>(); DecomposeAndConditions(list[i], list2); RangeVariable.RangeVariableConditions conditions2 = new RangeVariable.RangeVariableConditions(conditions); this.SetIndexConditions(conditions2, list2, rangeVarIndex, false); array[i] = conditions2; if (!conditions2.HasIndexCondition()) { return(false); } } Expression left = null; for (int j = 0; j < array.Length; j++) { RangeVariable.RangeVariableConditions conditions3 = array[j]; array[j].ExcludeConditions = left; if (j > 1) { Expression excludeConditions = array[j - 1].ExcludeConditions; left = new ExpressionLogical(50, left, excludeConditions); } if (conditions3.IndexCond != null) { for (int k = 0; k < conditions3.IndexedColumnCount; k++) { left = ExpressionLogical.AndExpressions(left, conditions3.IndexCond[k]); } } left = ExpressionLogical.AndExpressions(ExpressionLogical.AndExpressions(left, conditions3.IndexEndCondition), conditions3.NonIndexCondition); } if (conditions.IsJoin) { conditions.RangeVar.JoinConditions = array; array = new RangeVariable.RangeVariableConditions[list.Count]; ArrayUtil.FillArray(array, conditions.RangeVar.WhereConditions[0]); conditions.RangeVar.WhereConditions = array; } else { conditions.RangeVar.WhereConditions = array; array = new RangeVariable.RangeVariableConditions[list.Count]; ArrayUtil.FillArray(array, conditions.RangeVar.JoinConditions[0]); conditions.RangeVar.JoinConditions = array; } return(true); }
public void AddIndexCondition(Expression[] exprList, Index index, int colCount) { this.RangeIndex = index; this.OpType = exprList[0].GetExprType(); switch (this.OpType) { case 0x29: case 0x2f: this.IndexCond = exprList; this.IndexEndCond = new Expression[exprList.Length]; for (int i = 0; i < colCount; i++) { Expression expression = exprList[i]; this.IndexEndCond[i] = expression; this.IndexEndCondition = ExpressionLogical.AndExpressions(this.IndexEndCondition, expression); this.OpType = expression.GetExprType(); } this.OpTypeEnd = this.OpType; break; case 0x2a: case 0x2b: this.IndexCond = exprList; this.IndexEndCond = new Expression[exprList.Length]; this.OpTypeEnd = 0x4a; break; case 0x2c: case 0x2d: { Expression leftNode = exprList[0].GetLeftNode(); leftNode = new ExpressionLogical(0x2f, leftNode); leftNode = new ExpressionLogical(0x30, leftNode); this.IndexCond = new Expression[] { leftNode }; this.IndexEndCond = new Expression[exprList.Length]; this.IndexEndCond[0] = this.IndexEndCondition = exprList[0]; this.OpTypeEnd = this.OpType; this.OpType = 0x30; break; } case 0x30: this.IndexCond = exprList; this.IndexEndCond = new Expression[exprList.Length]; this.OpTypeEnd = 0x4a; break; default: throw Error.RuntimeError(0xc9, "RangeVariable"); } this.IndexedColumnCount = colCount; }
public void ReverseIndexCondition() { if ((this.OpType != 0x29) && (this.OpType != 0x2f)) { this.IndexEndCondition = null; for (int i = 0; i < this.IndexedColumnCount; i++) { Expression expression = this.IndexCond[i]; this.IndexCond[i] = this.IndexEndCond[i]; this.IndexEndCond[i] = expression; this.IndexEndCondition = ExpressionLogical.AndExpressions(this.IndexEndCondition, expression); } this.OpType = this.OpTypeEnd; this.Reversed = true; } }
public void AddCondition(Expression e) { if (e != null) { this.NonIndexCondition = ExpressionLogical.AndExpressions(this.NonIndexCondition, e); if (Expression.ExprFalse.Equals(this.NonIndexCondition)) { this.IsFalse = true; } if (((this.RangeIndex != null) && (this.RangeIndex.GetColumnCount() != 0)) && ((this.IndexedColumnCount != 0) && (e.GetIndexableExpression(this.RangeVar) != null))) { int columnIndex = e.GetLeftNode().GetColumnIndex(); int exprType = e.GetExprType(); if ((exprType - 0x2a) > 1) { if ((exprType - 0x2c) > 1) { return; } } else { if (this.OpType != 0x30) { this.AddToIndexConditions(e); return; } if (this.RangeIndex.GetColumns()[this.IndexedColumnCount - 1] == columnIndex) { this.NonIndexCondition = ExpressionLogical.AndExpressions(this.NonIndexCondition, this.IndexCond[this.IndexedColumnCount - 1]); this.IndexCond[this.IndexedColumnCount - 1] = e; this.OpType = e.OpType; } return; } if ((((this.OpType == 0x2b) || (this.OpType == 0x2a)) || (this.OpType == 0x30)) && ((this.OpTypeEnd == 0x4a) && (this.RangeIndex.GetColumns()[this.IndexedColumnCount - 1] == columnIndex))) { this.IndexEndCond[this.IndexedColumnCount - 1] = e; this.IndexEndCondition = ExpressionLogical.AndExpressions(this.IndexEndCondition, e); this.OpTypeEnd = e.GetExprType(); } } } }
public void AddJoinCondition(Expression e) { this.JoinCondition = ExpressionLogical.AndExpressions(this.JoinCondition, e); }
private void SetIndexConditions(RangeVariable.RangeVariableConditions conditions, List <Expression> exprList, int rangeVarIndex, bool includeOr) { this._colIndexSetEqual.Clear(); this._colIndexSetOther.Clear(); int num = 0; int count = exprList.Count; while (num < count) { Expression expression = exprList[num]; if ((expression != null) && expression.IsIndexable(conditions.RangeVar)) { switch (expression.GetExprType()) { case 0x29: if (((expression.ExprSubType != 0x34) && (expression.ExprSubType != 0x33)) && (expression.GetLeftNode().GetRangeVariable() == conditions.RangeVar)) { int columnIndex = expression.GetLeftNode().GetColumnIndex(); this._colIndexSetEqual.Add(columnIndex); } goto Label_01C9; case 0x2a: case 0x2b: case 0x2c: case 0x2d: if (expression.GetLeftNode().GetRangeVariable() == conditions.RangeVar) { int num8; int columnIndex = expression.GetLeftNode().GetColumnIndex(); if (!this._colIndexSetOther.TryGetValue(columnIndex, out num8)) { num8 = 0; } this._colIndexSetOther[columnIndex] = num8 + 1; } goto Label_01C9; case 0x2f: if (expression.GetLeftNode().GetRangeVariable() == conditions.RangeVar) { int columnIndex = expression.GetLeftNode().GetColumnIndex(); this._colIndexSetEqual.Add(columnIndex); } goto Label_01C9; case 0x30: if (expression.GetLeftNode().GetLeftNode().GetRangeVariable() == conditions.RangeVar) { int num11; int columnIndex = expression.GetLeftNode().GetLeftNode().GetColumnIndex(); if (!this._colIndexSetOther.TryGetValue(columnIndex, out num11)) { num11 = 0; } this._colIndexSetOther[columnIndex] = num11 + 1; } goto Label_01C9; case 50: case 2: goto Label_01C9; } Error.RuntimeError(0xc9, "RangeVariableResolver"); } Label_01C9: num++; } this.SetEqaulityConditions(conditions, exprList); if (!conditions.HasIndexCondition()) { this.SetNonEqualityConditions(conditions, exprList); } bool flag = conditions.HasIndexCondition(); bool flag2 = false; if (!flag & includeOr) { int num12 = 0; int num13 = exprList.Count; while (num12 < num13) { Expression expression2 = exprList[num12]; if (expression2 != null) { if (expression2.GetExprType() == 50) { flag = expression2.IsIndexable(conditions.RangeVar); if (flag) { flag = this.SetOrConditions(conditions, (ExpressionLogical)expression2, rangeVarIndex); } if (!flag) { goto Label_02FC; } exprList[num12] = null; flag2 = true; break; } if (((expression2.GetExprType() == 0x29) && (expression2.ExprSubType == 0x34)) && !expression2.GetRightNode().IsCorrelated()) { OrderedIntHashSet set = new OrderedIntHashSet(); ((ExpressionLogical)expression2).AddLeftColumnsForAllAny(conditions.RangeVar, set); if ((conditions.RangeVar.RangeTable.GetIndexForColumns(this.session, set, false) != null) && (this._inExpressions[rangeVarIndex] == null)) { this._inExpressions[rangeVarIndex] = expression2; this._inInJoin[rangeVarIndex] = conditions.IsJoin; this._inExpressionCount++; exprList[num12] = null; break; } } } Label_02FC: num12++; } } int num3 = 0; int num4 = exprList.Count; while (num3 < num4) { Expression expression3 = exprList[num3]; if (expression3 != null) { if (flag2) { for (int i = 0; i < conditions.RangeVar.JoinConditions.Length; i++) { if (conditions.IsJoin) { conditions.RangeVar.JoinConditions[i].NonIndexCondition = ExpressionLogical.AndExpressions(expression3, conditions.RangeVar.JoinConditions[i].NonIndexCondition); } else { conditions.RangeVar.WhereConditions[i].NonIndexCondition = ExpressionLogical.AndExpressions(expression3, conditions.RangeVar.WhereConditions[i].NonIndexCondition); } } } else { conditions.AddCondition(expression3); } } num3++; } }
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); }
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); }