internal override object Eval(DataRow row, DataRowVersion version) { if ((this.column == null) || (this.relation == null)) { throw ExprException.ExpressionUnbound(this.ToString()); } DataRow parentRow = row.GetParentRow(this.relation, version); if (parentRow == null) { return(DBNull.Value); } return(parentRow[this.column, parentRow.HasVersion(version) ? version : DataRowVersion.Current]); }
internal override void Bind(DataTable table, List <DataColumn> list) { BindTable(table); Check(); // special case for the Convert function bind only the first argument: // the second argument should be a Type stored as a name node, replace it with constant. if (s_funcs[_info]._id == FunctionId.Convert) { if (_argumentCount != 2) { throw ExprException.FunctionArgumentCount(_name); } _arguments ![0].Bind(table, list);
/// <summary> /// Parses given name and checks it validity /// </summary> internal static string ParseName(char[] text, int start, int pos) { char esc = '\0'; string charsToEscape = string.Empty; int saveStart = start; int savePos = pos; if (text[start] == '`') { start = checked ((start + 1)); pos = checked ((pos - 1)); esc = '\\'; charsToEscape = "`"; } else if (text[start] == '[') { start = checked ((start + 1)); pos = checked ((pos - 1)); esc = '\\'; charsToEscape = "]\\"; } if (esc != '\0') { // scan the name in search for the ESC int posEcho = start; for (int i = start; i < pos; i++) { if (text[i] == esc) { if (i + 1 < pos && charsToEscape.Contains(text[i + 1])) { i++; } } text[posEcho] = text[i]; posEcho++; } pos = posEcho; } if (pos == start) { throw ExprException.InvalidName(new string(text, saveStart, savePos - saveStart)); } return(new string(text, start, pos - start)); }
internal override void Bind(DataTable table, List <DataColumn> list) { BindTable(table); if (table == null) { throw ExprException.UnboundName(_name); } try { _column = table.Columns[_name]; } catch (Exception e) { _found = false; if (!Common.ADP.IsCatchableExceptionType(e)) { throw; } throw ExprException.UnboundName(_name); } if (_column == null) { throw ExprException.UnboundName(_name); } _name = _column.ColumnName; _found = true; // add column to the dependency list, do not add duplicate columns Debug.Assert(_column != null, "Failed to bind column " + _name); int i; for (i = 0; i < list.Count; i++) { // walk the list, check if the current column already on the list DataColumn dataColumn = list[i]; if (_column == dataColumn) { break; } } if (i >= list.Count) { list.Add(_column); } }
internal AggregateNode(FunctionId aggregateType, string columnName, bool local, string relationName) { Debug.Assert(columnName != null, "Invalid parameter columnName (null)."); #if DEBUG if (CompModSwitches.AggregateNode.TraceVerbose) { Debug.WriteLine("Creating the aggregate node"); } #endif this.aggregate = (Aggregate)(int)aggregateType; if (aggregateType == FunctionId.Sum) { this.type = AggregateType.Sum; } else if (aggregateType == FunctionId.Avg) { this.type = AggregateType.Mean; } else if (aggregateType == FunctionId.Min) { this.type = AggregateType.Min; } else if (aggregateType == FunctionId.Max) { this.type = AggregateType.Max; } else if (aggregateType == FunctionId.Count) { this.type = AggregateType.Count; } else if (aggregateType == FunctionId.Var) { this.type = AggregateType.Var; } else if (aggregateType == FunctionId.StDev) { this.type = AggregateType.StDev; } else { throw ExprException.UndefinedFunction(Function.FunctionName[(Int32)aggregateType]); } this.local = local; this.relationName = relationName; this.columnName = columnName; }
private ExpressionNode ParseAggregateArgument(FunctionId aggregate) { string str; string str2; bool flag; this.Scan(); try { if (this.token != Tokens.Child) { if (this.token != Tokens.Name) { throw ExprException.AggregateArgument(); } str = NameNode.ParseName(this.text, this.start, this.pos); this.ScanToken(Tokens.RightParen); return(new AggregateNode(this._table, aggregate, str)); } flag = this.token == Tokens.Child; this.prevOperand = 1; this.Scan(); if (this.token == Tokens.LeftParen) { this.ScanToken(Tokens.Name); str2 = NameNode.ParseName(this.text, this.start, this.pos); this.ScanToken(Tokens.RightParen); this.ScanToken(Tokens.Dot); } else { str2 = null; this.CheckToken(Tokens.Dot); } this.ScanToken(Tokens.Name); str = NameNode.ParseName(this.text, this.start, this.pos); this.ScanToken(Tokens.RightParen); } catch (Exception exception) { if (!ADP.IsCatchableExceptionType(exception)) { throw; } throw ExprException.AggregateArgument(); } return(new AggregateNode(this._table, aggregate, str, !flag, str2)); }
internal override object Eval(DataRow row, DataRowVersion version) { if (!this.found) { throw ExprException.UnboundName(this.name); } if (row != null) { return(this.column[row.GetRecordFromVersion(version)]); } if (!this.IsTableConstant()) { throw ExprException.UnboundName(this.name); } return(this.column.DataExpression.Evaluate()); }
internal override object Eval(DataRow row, DataRowVersion version) { if (_column == null || _relation == null) { throw ExprException.ExpressionUnbound(ToString()); } DataRow parent = row.GetParentRow(_relation, version); if (parent == null) { return(DBNull.Value); } return(parent[_column, parent.HasVersion(version) ? version : DataRowVersion.Current]); }
internal virtual void Check() { #if DEBUG if (CompModSwitches.FunctionNode.TraceVerbose) { Debug.WriteLine("Check function: " + this.name); } #endif Function f = funcs[info]; #if DEBUG if (CompModSwitches.FunctionNode.TraceVerbose) { Debug.WriteLine("id = " + ((int)f.id).ToString()); } if (CompModSwitches.FunctionNode.TraceVerbose) { Debug.WriteLine(", arguments = " + this.argumentCount.ToString()); } #endif if (this.info < 0) { throw ExprException.UndefinedFunction(this.name); } if (funcs[info].IsVariantArgumentList) { // for finctions with variabls argument list argumentCount is a minimal number of arguments if (argumentCount < funcs[info].argumentCount) { // Special case for the IN operator if (funcs[this.info].id == FunctionId.In) { throw ExprException.InWithoutList(); } throw ExprException.FunctionArgumentCount(this.name); } } else { if (argumentCount != funcs[info].argumentCount) { throw ExprException.FunctionArgumentCount(this.name); } } }
internal override object Eval(DataRow row, DataRowVersion version) { object[] argumentValues = new object[this.argumentCount]; if (funcs[this.info].id == FunctionId.Convert) { if (this.argumentCount != 2) { throw ExprException.FunctionArgumentCount(this.name); } argumentValues[0] = this.arguments[0].Eval(row, version); argumentValues[1] = this.GetDataType(this.arguments[1]); } else if (funcs[this.info].id != FunctionId.Iif) { for (int i = 0; i < this.argumentCount; i++) { argumentValues[i] = this.arguments[i].Eval(row, version); if (funcs[this.info].IsValidateArguments) { if ((argumentValues[i] == DBNull.Value) || (typeof(object) == funcs[this.info].parameters[i])) { return(DBNull.Value); } if (argumentValues[i].GetType() != funcs[this.info].parameters[i]) { if ((funcs[this.info].parameters[i] == typeof(int)) && ExpressionNode.IsInteger(DataStorage.GetStorageType(argumentValues[i].GetType()))) { argumentValues[i] = Convert.ToInt32(argumentValues[i], base.FormatProvider); } else { if (((funcs[this.info].id != FunctionId.Trim) && (funcs[this.info].id != FunctionId.Substring)) && (funcs[this.info].id != FunctionId.Len)) { throw ExprException.ArgumentType(funcs[this.info].name, i + 1, funcs[this.info].parameters[i]); } if ((typeof(string) != argumentValues[i].GetType()) && (typeof(SqlString) != argumentValues[i].GetType())) { throw ExprException.ArgumentType(funcs[this.info].name, i + 1, funcs[this.info].parameters[i]); } } } } } } return(this.EvalFunction(funcs[this.info].id, argumentValues, row, version)); }
internal FunctionNode(DataTable table, string name) : base(table) { _name = name; for (int i = 0; i < s_funcs.Length; i++) { if (string.Equals(s_funcs[i]._name, name, StringComparison.OrdinalIgnoreCase)) { // we found the reserved word.. _info = i; break; } } if (_info < 0) { throw ExprException.UndefinedFunction(_name); } }
internal FunctionNode(DataTable table, string name) : base(table) { this.name = name; for (int i = 0; i < funcs.Length; i++) { if (String.Compare(funcs[i].name, name, StringComparison.OrdinalIgnoreCase) == 0) { // we found the reserved word.. this.info = i; break; } } if (this.info < 0) { throw ExprException.UndefinedFunction(this.name); } }
// Helper for the DataTable.Compute method internal override object Eval(int[] records) { #if DEBUG if (CompModSwitches.AggregateNode.TraceVerbose) { Debug.WriteLine("Eval " + this.ToString()); } #endif if (table == null) { throw ExprException.AggregateUnbound(this.ToString()); } if (!local) { throw ExprException.ComputeNotAggregate(this.ToString()); } return(column.GetAggregateValue(records, type)); }
internal void AddArgument(ExpressionNode argument) { if (!funcs[this.info].IsVariantArgumentList && (this.argumentCount >= funcs[this.info].argumentCount)) { throw ExprException.FunctionArgumentCount(this.name); } if (this.arguments == null) { this.arguments = new ExpressionNode[1]; } else if (this.argumentCount == this.arguments.Length) { ExpressionNode[] destinationArray = new ExpressionNode[this.argumentCount * 2]; Array.Copy(this.arguments, 0, destinationArray, 0, this.argumentCount); this.arguments = destinationArray; } this.arguments[this.argumentCount++] = argument; }
private void ScanDate() { char[] text = this.text; do { this.pos++; }while ((this.pos < text.Length) && (text[this.pos] != '#')); if ((this.pos >= text.Length) || (text[this.pos] != '#')) { if (this.pos >= text.Length) { throw ExprException.InvalidDate(new string(text, this.start, (this.pos - 1) - this.start)); } throw ExprException.InvalidDate(new string(text, this.start, this.pos - this.start)); } this.token = Tokens.Date; this.pos++; }
private void ScanName(char chEnd, char esc, string charsToEscape) { char[] text = this.text; do { if (((text[this.pos] == esc) && ((this.pos + 1) < text.Length)) && (charsToEscape.IndexOf(text[this.pos + 1]) >= 0)) { this.pos++; } this.pos++; }while ((this.pos < text.Length) && (text[this.pos] != chEnd)); if (this.pos >= text.Length) { throw ExprException.InvalidNameBracketing(new string(text, this.start, (this.pos - 1) - this.start)); } this.pos++; this.token = Tokens.Name; }
internal override ExpressionNode Optimize() { for (int i = 0; i < this.argumentCount; i++) { this.arguments[i] = this.arguments[i].Optimize(); } if (funcs[this.info].id == FunctionId.In) { if (!this.IsConstant()) { throw ExprException.NonConstantArgument(); } } else if (this.IsConstant()) { return(new ConstNode(base.table, System.Data.ValueType.Object, this.Eval(), false)); } return(this); }
internal void AddArgument(ExpressionNode argument) { if (!funcs[info].IsVariantArgumentList && argumentCount >= funcs[info].argumentCount) { throw ExprException.FunctionArgumentCount(this.name); } if (arguments == null) { arguments = new ExpressionNode[initialCapacity]; } else if (argumentCount == arguments.Length) { ExpressionNode[] bigger = new ExpressionNode[argumentCount * 2]; System.Array.Copy(arguments, 0, bigger, 0, argumentCount); arguments = bigger; } arguments[argumentCount++] = argument; }
internal override ExpressionNode Optimize() { for (int i = 0; i < this.argumentCount; i++) { this.arguments[i] = this.arguments[i].Optimize(); } Debug.Assert(this.info > 0, "Optimizing unbound function "); if (funcs[this.info].id == FunctionId.In) { // we can not optimize the in node, just check that it has all constant arguments // CONSIDER : can not find better place for this.. check that the IN arguments are all constants if (!this.IsConstant()) { throw ExprException.NonConstantArgument(); } } else { if (this.IsConstant()) { #if DEBUG if (CompModSwitches.FunctionNode.TraceVerbose) { Debug.WriteLine("CONSTANT function node " + this.ToString()); } #endif return(new ConstNode(ValueType.Object, this.Eval(), false)); } #if DEBUG else { if (CompModSwitches.FunctionNode.TraceVerbose) { Debug.WriteLine("Can not optimize the function call"); } } #endif } return(this); }
internal void AddArgument(ExpressionNode argument) { if (!s_funcs[_info]._isVariantArgumentList && _argumentCount >= s_funcs[_info]._argumentCount) { throw ExprException.FunctionArgumentCount(_name); } if (_arguments == null) { _arguments = new ExpressionNode[initialCapacity]; } else if (_argumentCount == _arguments.Length) { ExpressionNode[] bigger = new ExpressionNode[_argumentCount * 2]; Array.Copy(_arguments, bigger, _argumentCount); _arguments = bigger; } _arguments[_argumentCount++] = argument; }
internal override void Bind(DataTable table, List <DataColumn> list) { base.BindTable(table); if (table == null) { throw ExprException.UnboundName(this.name); } try { this.column = table.Columns[this.name]; } catch (Exception exception) { this.found = false; if (!ADP.IsCatchableExceptionType(exception)) { throw; } throw ExprException.UnboundName(this.name); } if (this.column == null) { throw ExprException.UnboundName(this.name); } this.name = this.column.ColumnName; this.found = true; int num = 0; while (num < list.Count) { DataColumn column = list[num]; if (this.column == column) { break; } num++; } if (num >= list.Count) { list.Add(this.column); } }
internal AggregateNode(DataTable?table, FunctionId aggregateType, string columnName, bool local, string?relationName) : base(table) { Debug.Assert(columnName != null, "Invalid parameter column name (null)."); _aggregate = (Aggregate)(int)aggregateType; if (aggregateType == FunctionId.Sum) { _type = AggregateType.Sum; } else if (aggregateType == FunctionId.Avg) { _type = AggregateType.Mean; } else if (aggregateType == FunctionId.Min) { _type = AggregateType.Min; } else if (aggregateType == FunctionId.Max) { _type = AggregateType.Max; } else if (aggregateType == FunctionId.Count) { _type = AggregateType.Count; } else if (aggregateType == FunctionId.Var) { _type = AggregateType.Var; } else if (aggregateType == FunctionId.StDev) { _type = AggregateType.StDev; } else { throw ExprException.UndefinedFunction(Function.s_functionName[(int)aggregateType]); } _local = local; _relationName = relationName; _columnName = columnName; }
private bool AcceptRecord(int record) { DataRow row = table.recordManager[record]; if (row == null) { return(true); } // DataRowVersion version = DataRowVersion.Default; if (row.oldRecord == record) { version = DataRowVersion.Original; } else if (row.newRecord == record) { version = DataRowVersion.Current; } else if (row.tempRecord == record) { version = DataRowVersion.Proposed; } object val = this.linearExpression.Eval(row, version); bool result; try { result = DataExpression.ToBoolean(val); } catch (Exception e) { // if (!ADP.IsCatchableExceptionType(e)) { throw; } throw ExprException.FilterConvertion(this.rowFilter.Expression); } return(result); }
internal override object Eval(DataRow?row, DataRowVersion version) { if (!_found) { throw ExprException.UnboundName(_name); } if (row == null) { if (IsTableConstant()) // this column is TableConstant Aggregate Function { return(_column !.DataExpression !.Evaluate()); } else { throw ExprException.UnboundName(_name); } } return(_column ![row.GetRecordFromVersion(version)]);
internal static string ParseName(char[] text, int start, int pos) { char ch = '\0'; string str = ""; int startIndex = start; int num4 = pos; if (text[start] == '`') { start++; pos--; ch = '\\'; str = "`"; } else if (text[start] == '[') { start++; pos--; ch = '\\'; str = @"]\"; } if (ch != '\0') { int index = start; for (int i = start; i < pos; i++) { if (((text[i] == ch) && ((i + 1) < pos)) && (str.IndexOf(text[i + 1]) >= 0)) { i++; } text[index] = text[i]; index++; } pos = index; } if (pos == start) { throw ExprException.InvalidName(new string(text, startIndex, num4 - startIndex)); } return(new string(text, start, pos - start)); }
internal object Evaluate(DataRow row, DataRowVersion version) { object result; if (!bound) { this.Bind(this.table); } if (expr != null) { result = expr.Eval(row, version); // if the type is a SqlType (StorageType.Uri < _storageType), convert DBNull values. if (result != DBNull.Value || StorageType.Uri < _storageType) { // we need to convert the return value to the column.Type; try { if (StorageType.Object != _storageType) { result = SqlConvert.ChangeType2(result, _storageType, _dataType, table.FormatProvider); } } catch (Exception e) { // if (!ADP.IsCatchableExceptionType(e)) { throw; } ExceptionBuilder.TraceExceptionForCapture(e); // throw ExprException.DatavalueConvertion(result, _dataType, e); } } } else { result = null; } return(result); }
private void ScanString(char escape) { char[] text = this.text; while (this.pos < text.Length) { char ch = text[this.pos++]; if (((ch == escape) && (this.pos < text.Length)) && (text[this.pos] == escape)) { this.pos++; } else if (ch == escape) { break; } } if (this.pos >= text.Length) { throw ExprException.InvalidString(new string(text, this.start, (this.pos - 1) - this.start)); } this.token = Tokens.StringConst; }
/// <include file='doc\DataFilter.uex' path='docs/doc[@for="DataFilter.Invoke2"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public virtual bool Invoke(DataRow row, DataRowVersion version) { if (expr == null) { return(true); } if (row == null) { throw ExprException.InvokeArgument(); } object val = expr.Eval(row, version); bool result; try { result = ToBoolean(val); } catch (Exception) { throw ExprException.FilterConvertion(Expression); } return(result); }
internal override object Eval(DataRow row, DataRowVersion version) { #if DEBUG if (CompModSwitches.LookupNode.TraceVerbose) { Debug.WriteLine("Eval " + this.ToString()); } #endif if (table == null || column == null || relation == null) { throw ExprException.ExpressionUnbound(this.ToString()); } DataRow parent = row.GetParentRow(relation, version); if (parent == null) { return(DBNull.Value); } return(parent[column, parent.HasVersion(version) ? version : DataRowVersion.Current]); // haroona : Bug 76154 }
private bool AcceptRecord(int record) { bool flag; DataRow row = this.table.recordManager[record]; if (row == null) { return(true); } DataRowVersion original = DataRowVersion.Default; if (row.oldRecord == record) { original = DataRowVersion.Original; } else if (row.newRecord == record) { original = DataRowVersion.Current; } else if (row.tempRecord == record) { original = DataRowVersion.Proposed; } object obj2 = this.linearExpression.Eval(row, original); try { flag = DataExpression.ToBoolean(obj2); } catch (Exception exception) { if (!ADP.IsCatchableExceptionType(exception)) { throw; } throw ExprException.FilterConvertion(this.rowFilter.Expression); } return(flag); }