internal override object Eval(DataRow row, DataRowVersion version) { #if DEBUG if (CompModSwitches.AggregateNode.TraceVerbose) { Debug.WriteLine("Eval " + this.ToString() + ", version " + version.ToString()); } #endif if (table == null) { throw ExprException.AggregateUnbound(this.ToString()); } DataRow[] rows; if (local) { rows = new DataRow[table.Rows.Count]; table.Rows.CopyTo(rows, 0); } else { if (row == null) { throw ExprException.EvalNoContext(); } if (relation == null) { throw ExprException.AggregateUnbound(this.ToString()); } rows = row.GetChildRows(relation, version); } #if DEBUG if (CompModSwitches.AggregateNode.TraceVerbose) { Debug.WriteLine("Eval " + this.ToString() + ", # of Rows: " + rows.Length.ToString()); } #endif int[] records; if (version == DataRowVersion.Proposed) { version = DataRowVersion.Default; } records = new int[rows.Length]; for (int i = 0; i < rows.Length; i++) { records[i] = rows[i].GetRecordFromVersion(version); } return(column.GetAggregateValue(records, type)); }
// IDataParameter.SourceVersion static internal ArgumentOutOfRangeException InvalidDataRowVersion(DataRowVersion value) { #if DEBUG switch (value) { case DataRowVersion.Default: case DataRowVersion.Current: case DataRowVersion.Original: case DataRowVersion.Proposed: Debug.Assert(false, "valid DataRowVersion " + value.ToString()); break; } #endif return(InvalidEnumerationValue(typeof(DataRowVersion), (int)value)); }
public override string GetCommand(Column column, string parameterName, System.Data.ParameterDirection parameterDirection, DataRowVersion dataRowVersion, bool isNullable) { SqlDbType sqlDbType = (SqlDbType)Enum.Parse(typeof(SqlDbType), column.OriginalSQLType); return(string.Format("System.Data.SqlClient.SqlParameter(\"{0}\", System.Data.SqlDbType.{1}, {2}, System.Data.ParameterDirection.{3}, {4}, (System.Byte)({5}), (System.Byte)({6}), \"{7}\", System.Data.DataRowVersion.{8}, null)", parameterName, /*The name of the parameter*/ sqlDbType.ToString(), /*One of the OleDbType values*/ column.Length.ToString(), /*The length of the parameter*/ parameterDirection.ToString(), /*One of the ParameterDirection values*/ isNullable.ToString(), column.Precision.ToString(), /*The total number of digits to the left and right of the decimal point to which Value is resolved*/ column.Scale.ToString(), /*The total number of decimal places to which Value is resolved*/ column.Name, /*The name of the source column*/ dataRowVersion.ToString() )); }
public override string GetCommand(Column column, string parameterName, System.Data.ParameterDirection parameterDirection, DataRowVersion dataRowVersion, bool isNullable) { OleDbType oleDbType = (OleDbType)Enum.Parse(typeof(OleDbType), column.OriginalSQLType); return string.Format("System.Data.OleDb.OleDbParameter(\"{0}\", System.Data.OleDb.OleDbType.{1}, {2}, System.Data.ParameterDirection.{3}, {4}, (System.Byte)({5}), (System.Byte)({6}), \"{7}\", System.Data.DataRowVersion.{8}, null)", parameterName, /*The name of the parameter*/ oleDbType.ToString(), /*One of the OleDbType values*/ column.Length.ToString(), /*The length of the parameter*/ parameterDirection.ToString(), /*One of the ParameterDirection values*/ isNullable.ToString(), column.Precision.ToString(), /*The total number of digits to the left and right of the decimal point to which Value is resolved*/ column.Scale.ToString(), /*The total number of decimal places to which Value is resolved*/ column.Name, /*The name of the source column*/ dataRowVersion.ToString() ); }
internal static ArgumentOutOfRangeException InvalidDataRowVersion (DataRowVersion value) { object [] args = new object [] { "DataRowVersion", value.ToString () } ; return new ArgumentOutOfRangeException (GetExceptionMessage ("{0}: Invalid DataRow Version enumeration value: {1}",args)); }
internal static ArgumentOutOfRangeException InvalidDataRowVersion(DataRowVersion value) { object [] args = new object [] { "DataRowVersion", value.ToString() }; return(new ArgumentOutOfRangeException(GetExceptionMessage("{0}: Invalid DataRow Version enumeration value: {1}", args))); }
internal virtual void Evaluate(DataRow row, DataRowVersion version) { #if DEBUG if (CompModSwitches.DataExpression.TraceVerbose) { Debug.WriteLine("Evaluate expression column Queue, version = " + version.ToString() + " for table " + owner.TableName); } #endif Debug.Assert(columns != null, "Invalid dependensy list"); Debug.Assert(row != null, "Invalid argument to Evaluate, row"); for (int i = 0; i < columnCount; i++) { DataColumn col = columns[i]; Debug.Assert(col.Computed, "Only computed columns should be in the queue."); #if DEBUG if (CompModSwitches.DataExpression.TraceVerbose) { Debug.WriteLine("Evaluate column " + col.ColumnName + " = " + col.DataExpression.ToString()); } #endif if (col.Table == null) { continue; } if (col.Table != owner) { // first if the column belongs to an other table we need to recalc it for each row in the foreing table #if DEBUG if (CompModSwitches.DataExpression.TraceVerbose) { Debug.WriteLine("the column belong to a different table %%%%%%%"); } #endif // we need to update all foreign table - NOPE, only those who are valid parents. ALTHOUGH we're skipping old parents right now... confirm. DataRowVersion foreignVer = (version == DataRowVersion.Proposed) ? DataRowVersion.Default : version; int parentRelationCount = owner.ParentRelations.Count; for (int j = 0; j < parentRelationCount; j++) { DataRelation relation = owner.ParentRelations[j]; if (relation.ParentTable != col.Table) { continue; } DataRow parentRow = row.GetParentRow(relation, version); if (parentRow != null) { col[parentRow.GetRecordFromVersion(foreignVer)] = col.DataExpression.Evaluate(parentRow, foreignVer); } } int childRelationCount = owner.ChildRelations.Count; for (int j = 0; j < childRelationCount; j++) { DataRelation relation = owner.ChildRelations[j]; if (relation.ChildTable != col.Table) { continue; } DataRow[] childRows = row.GetChildRows(relation, version); for (int k = 0; k < childRows.Length; k++) { if (childRows[k] != null) { col[childRows[k].GetRecordFromVersion(foreignVer)] = col.DataExpression.Evaluate(childRows[k], foreignVer); } } } } else if (col.DataExpression.HasLocalAggregate()) { // if column expression references a local Table aggregate we need to recalc it for the each row in the local table DataRowVersion aggVersion = (version == DataRowVersion.Proposed) ? DataRowVersion.Default : version; #if DEBUG if (CompModSwitches.DataExpression.TraceVerbose) { Debug.WriteLine("it has local aggregate."); } #endif bool isConst = col.DataExpression.IsTableAggregate(); object val = null; if (isConst) { val = col.DataExpression.Evaluate(row, aggVersion); } DataRow[] rows = new DataRow[col.Table.Rows.Count]; col.Table.Rows.CopyTo(rows, 0); for (int j = 0; j < rows.Length; j++) { if (!isConst) { val = col.DataExpression.Evaluate(rows[j], aggVersion); } col[rows[j].GetRecordFromVersion(aggVersion)] = val; } } else { col[row.GetRecordFromVersion(version)] = col.DataExpression.Evaluate(row, version); } } }