1 //------------------------------------------------------------------------------
2 // <copyright file="DataTableReader.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 // <owner current="true" primary="false">Microsoft</owner>
7 // <owner current="false" primary="false">Microsoft</owner>
8 //------------------------------------------------------------------------------
10 namespace System.Data {
12 using System.Data.Common;
13 using System.Data.SqlTypes;
14 using System.Collections;
15 using System.ComponentModel;
17 public sealed class DataTableReader : DbDataReader {
19 private readonly DataTable[] tables = null;
20 private bool isOpen = true;
21 private DataTable schemaTable = null;
23 private int tableCounter = -1;
24 private int rowCounter = -1;
25 private DataTable currentDataTable = null;
26 private DataRow currentDataRow = null;
28 private bool hasRows= true;
29 private bool reachEORows = false;
30 private bool currentRowRemoved = false;
31 private bool schemaIsChanged = false;
32 private bool started = false;
33 private bool readerIsInvalid = false;
34 private DataTableReaderListener listener = null;
35 private bool tableCleared = false;
37 public DataTableReader(DataTable dataTable) {
38 if (dataTable == null)
39 throw ExceptionBuilder.ArgumentNull("DataTable");
40 tables = new DataTable[1] {dataTable};
43 // schemaTable = GetSchemaTableFromDataTable(currentDataTable);
46 public DataTableReader(DataTable [] dataTables) {
47 if (dataTables == null)
48 throw ExceptionBuilder.ArgumentNull("DataTable");
50 if (dataTables.Length == 0)
51 throw ExceptionBuilder.DataTableReaderArgumentIsEmpty();
54 tables = new DataTable[dataTables.Length];
55 for (int i = 0; i < dataTables.Length ; i++) {
56 if (dataTables[i] == null)
57 throw ExceptionBuilder.ArgumentNull("DataTable");
58 tables[i] = dataTables[i];
62 // schemaTable = GetSchemaTableFromDataTable(currentDataTable);
65 private bool ReaderIsInvalid {
67 return readerIsInvalid;
70 if (readerIsInvalid == value)
72 readerIsInvalid = value;
73 if (readerIsInvalid && listener != null) {
79 private bool IsSchemaChanged {
81 return schemaIsChanged;
84 if (!value || schemaIsChanged == value) //once it is set to false; should not change unless in init() or NextResult()
86 schemaIsChanged = value;
87 if (listener != null) {
93 internal DataTable CurrentDataTable {
95 return currentDataTable;
102 schemaIsChanged = false;
103 currentDataTable = tables[tableCounter];
104 hasRows = (currentDataTable.Rows.Count > 0);
105 ReaderIsInvalid = false;
107 // we need to listen to current tables event so create a listener, it will listen to events and call us back.
108 listener = new DataTableReaderListener(this);
112 override public void Close() {
115 // no need to listen to events after close
116 if (listener != null)
125 override public DataTable GetSchemaTable(){
126 ValidateOpen("GetSchemaTable");
129 // each time, we just get schema table of current table for once, no need to recreate each time, if schema is changed, reader is already
131 if (schemaTable == null)
132 schemaTable = GetSchemaTableFromDataTable(currentDataTable);
137 override public bool NextResult() {
138 // next result set; reset everything
139 ValidateOpen("NextResult");
141 if ((tableCounter == tables.Length -1))
144 currentDataTable = tables[++tableCounter];
146 if (listener != null)
147 listener.UpdataTable(currentDataTable); // it will unsubscribe from preveous tables events and subscribe to new table's events
151 currentRowRemoved = false;
153 schemaIsChanged = false;
155 ReaderIsInvalid = false;
156 tableCleared = false;
158 hasRows = (currentDataTable.Rows.Count > 0);
163 override public bool Read() {
165 /* else if (tableCleared) {
167 throw ExceptionBuilder.EmptyDataTableReader(currentDataTable.TableName);
174 ValidateRow(rowCounter);
177 ValidateOpen("Read");
186 if (rowCounter >= currentDataTable.Rows.Count -1 ) {
188 if (listener != null)
194 ValidateRow(rowCounter);
195 currentDataRow = currentDataTable.Rows[rowCounter];
197 while (currentDataRow.RowState == DataRowState.Deleted) {
199 if (rowCounter == currentDataTable.Rows.Count) {
201 if (listener != null)
205 ValidateRow(rowCounter);
206 currentDataRow = currentDataTable.Rows[rowCounter];
208 if (currentRowRemoved)
209 currentRowRemoved = false;
214 override public int Depth {
216 ValidateOpen("Depth");
222 override public bool IsClosed {
228 override public int RecordsAffected {
235 override public bool HasRows {
237 ValidateOpen("HasRows");
243 override public object this[int ordinal] {
245 ValidateOpen("Item");
247 if ((currentDataRow == null) || (currentDataRow.RowState == DataRowState.Deleted)) {
248 ReaderIsInvalid = true;
249 throw ExceptionBuilder.InvalidDataTableReader(currentDataTable.TableName);
252 return currentDataRow[ordinal];
254 catch(IndexOutOfRangeException e) { // thrown by DataColumnCollection
255 ExceptionBuilder.TraceExceptionWithoutRethrow(e);
256 throw ExceptionBuilder.ArgumentOutOfRange("ordinal");
261 override public object this[string name] {
263 ValidateOpen("Item");
265 if ((currentDataRow == null) || (currentDataRow.RowState == DataRowState.Deleted)) {
266 ReaderIsInvalid = true;
267 throw ExceptionBuilder.InvalidDataTableReader(currentDataTable.TableName);
269 return currentDataRow[name];
273 override public Int32 FieldCount {
275 ValidateOpen("FieldCount");
277 return currentDataTable.Columns.Count;
281 override public Type GetProviderSpecificFieldType(int ordinal) {
282 ValidateOpen("GetProviderSpecificFieldType");
284 return GetFieldType(ordinal);
287 override public Object GetProviderSpecificValue(int ordinal) {
288 ValidateOpen("GetProviderSpecificValue");
290 return GetValue(ordinal);
293 override public int GetProviderSpecificValues(object[] values) {
294 ValidateOpen("GetProviderSpecificValues");
296 return GetValues(values);
299 override public bool GetBoolean (int ordinal) {
300 ValidateState("GetBoolean");
303 return (bool) currentDataRow[ordinal];
305 catch(IndexOutOfRangeException e) { // thrown by DataColumnCollection
306 ExceptionBuilder.TraceExceptionWithoutRethrow(e);
307 throw ExceptionBuilder.ArgumentOutOfRange("ordinal");
311 override public byte GetByte (int ordinal) {
312 ValidateState("GetByte");
315 return (byte) currentDataRow[ordinal];
317 catch(IndexOutOfRangeException e) { // thrown by DataColumnCollection
318 ExceptionBuilder.TraceExceptionWithoutRethrow(e);
319 throw ExceptionBuilder.ArgumentOutOfRange("ordinal");
323 override public long GetBytes(int ordinal, long dataIndex, byte[] buffer, int bufferIndex, int length) {
324 ValidateState("GetBytes");
328 tempBuffer = (byte[]) currentDataRow[ordinal];
330 catch(IndexOutOfRangeException e) { // thrown by DataColumnCollection
331 ExceptionBuilder.TraceExceptionWithoutRethrow(e);
332 throw ExceptionBuilder.ArgumentOutOfRange("ordinal");
334 if (buffer == null) {
335 return tempBuffer.Length;
337 int srcIndex = (int) dataIndex;
338 int byteCount = Math.Min(tempBuffer.Length - srcIndex, length);
340 throw ADP.InvalidSourceBufferIndex(tempBuffer.Length, srcIndex, "dataIndex");
342 else if ((bufferIndex < 0) || (bufferIndex > 0 && bufferIndex >= buffer.Length)) {
343 throw ADP.InvalidDestinationBufferIndex(buffer.Length, bufferIndex, "bufferIndex");
347 Array.Copy(tempBuffer, dataIndex, buffer, bufferIndex, byteCount);
349 else if (length < 0) {
350 throw ADP.InvalidDataLength(length);
359 override public char GetChar (int ordinal) {
360 ValidateState("GetChar");
363 return (char) currentDataRow[ordinal];
365 catch(IndexOutOfRangeException e) { // thrown by DataColumnCollection
366 ExceptionBuilder.TraceExceptionWithoutRethrow(e);
367 throw ExceptionBuilder.ArgumentOutOfRange("ordinal");
371 override public long GetChars(int ordinal, long dataIndex, char[] buffer, int bufferIndex, int length) {
372 ValidateState("GetChars");
376 tempBuffer = (char[]) currentDataRow[ordinal];
378 catch(IndexOutOfRangeException e) { // thrown by DataColumnCollection
379 ExceptionBuilder.TraceExceptionWithoutRethrow(e);
380 throw ExceptionBuilder.ArgumentOutOfRange("ordinal");
383 if (buffer == null) {
384 return tempBuffer.Length;
387 int srcIndex = (int) dataIndex;
388 int charCount = Math.Min(tempBuffer.Length - srcIndex, length);
390 throw ADP.InvalidSourceBufferIndex(tempBuffer.Length, srcIndex, "dataIndex");
392 else if ((bufferIndex < 0) || (bufferIndex > 0 && bufferIndex >= buffer.Length)) {
393 throw ADP.InvalidDestinationBufferIndex(buffer.Length, bufferIndex, "bufferIndex");
397 Array.Copy(tempBuffer, dataIndex, buffer, bufferIndex, charCount);
399 else if (length < 0) {
400 throw ADP.InvalidDataLength(length);
408 override public String GetDataTypeName (int ordinal) {
409 ValidateOpen("GetDataTypeName");
411 return ((Type)GetFieldType(ordinal)).Name;
414 override public DateTime GetDateTime (int ordinal) {
415 ValidateState("GetDateTime");
418 return (DateTime) currentDataRow[ordinal];
420 catch(IndexOutOfRangeException e) { // thrown by DataColumnCollection
421 ExceptionBuilder.TraceExceptionWithoutRethrow(e);
422 throw ExceptionBuilder.ArgumentOutOfRange("ordinal");
426 override public Decimal GetDecimal (int ordinal) {
427 ValidateState("GetDecimal");
430 return (Decimal) currentDataRow[ordinal];
432 catch(IndexOutOfRangeException e) { // thrown by DataColumnCollection
433 ExceptionBuilder.TraceExceptionWithoutRethrow(e);
434 throw ExceptionBuilder.ArgumentOutOfRange("ordinal");
438 override public Double GetDouble (int ordinal) {
439 ValidateState("GetDouble");
442 return (double) currentDataRow[ordinal];
444 catch(IndexOutOfRangeException e) { // thrown by DataColumnCollection
445 ExceptionBuilder.TraceExceptionWithoutRethrow(e);
446 throw ExceptionBuilder.ArgumentOutOfRange("ordinal");
450 override public Type GetFieldType (int ordinal) {
451 ValidateOpen("GetFieldType");
454 return (currentDataTable.Columns[ordinal].DataType);
456 catch(IndexOutOfRangeException e) { // thrown by DataColumnCollection
457 ExceptionBuilder.TraceExceptionWithoutRethrow(e);
458 throw ExceptionBuilder.ArgumentOutOfRange("ordinal");
462 override public Single GetFloat (int ordinal) {
463 ValidateState("GetFloat");
466 return (Single) currentDataRow[ordinal];
468 catch(IndexOutOfRangeException e) { // thrown by DataColumnCollection
469 ExceptionBuilder.TraceExceptionWithoutRethrow(e);
470 throw ExceptionBuilder.ArgumentOutOfRange("ordinal");
474 override public Guid GetGuid (int ordinal) {
475 ValidateState("GetGuid");
478 return (Guid) currentDataRow[ordinal];
480 catch(IndexOutOfRangeException e) { // thrown by DataColumnCollection
481 ExceptionBuilder.TraceExceptionWithoutRethrow(e);
482 throw ExceptionBuilder.ArgumentOutOfRange("ordinal");
486 override public Int16 GetInt16 (int ordinal) {
487 ValidateState("GetInt16");
490 return (Int16) currentDataRow[ordinal];
492 catch(IndexOutOfRangeException e) { // thrown by DataColumnCollection
493 ExceptionBuilder.TraceExceptionWithoutRethrow(e);
494 throw ExceptionBuilder.ArgumentOutOfRange("ordinal");
498 override public Int32 GetInt32 (int ordinal) {
499 ValidateState("GetInt32");
502 return (Int32) currentDataRow[ordinal];
504 catch(IndexOutOfRangeException e) { // thrown by DataColumnCollection
505 ExceptionBuilder.TraceExceptionWithoutRethrow(e);
506 throw ExceptionBuilder.ArgumentOutOfRange("ordinal");
510 override public Int64 GetInt64 (int ordinal) {
511 ValidateState("GetInt64");
514 return (Int64) currentDataRow[ordinal];
516 catch(IndexOutOfRangeException e) { // thrown by DataColumnCollection
517 ExceptionBuilder.TraceExceptionWithoutRethrow(e);
518 throw ExceptionBuilder.ArgumentOutOfRange("ordinal");
522 override public String GetName (int ordinal) {
523 ValidateOpen("GetName");
526 return (currentDataTable.Columns[ordinal].ColumnName);
528 catch(IndexOutOfRangeException e) { // thrown by DataColumnCollection
529 ExceptionBuilder.TraceExceptionWithoutRethrow(e);
530 throw ExceptionBuilder.ArgumentOutOfRange("ordinal");
534 override public Int32 GetOrdinal (string name) {
535 ValidateOpen("GetOrdinal");
537 DataColumn dc = currentDataTable.Columns[name];
540 return dc.Ordinal;// WebData 113248
543 throw ExceptionBuilder.ColumnNotInTheTable(name, currentDataTable.TableName);
547 override public string GetString (int ordinal) {
548 ValidateState("GetString");
551 return (string) currentDataRow[ordinal];
553 catch(IndexOutOfRangeException e) { // thrown by DataColumnCollection
554 ExceptionBuilder.TraceExceptionWithoutRethrow(e);
555 throw ExceptionBuilder.ArgumentOutOfRange("ordinal");
560 override public object GetValue (int ordinal) {
561 ValidateState("GetValue");
564 return currentDataRow[ordinal];
566 catch(IndexOutOfRangeException e) { // thrown by DataColumnCollection
567 ExceptionBuilder.TraceExceptionWithoutRethrow(e);
568 throw ExceptionBuilder.ArgumentOutOfRange("ordinal");
572 override public Int32 GetValues (object[] values) {
573 ValidateState("GetValues");
577 throw ExceptionBuilder.ArgumentNull("values");
579 Array.Copy(currentDataRow.ItemArray, values, currentDataRow.ItemArray.Length > values.Length ? values.Length : currentDataRow.ItemArray.Length);
580 return (currentDataRow.ItemArray.Length > values.Length ? values.Length : currentDataRow.ItemArray.Length);
582 override public bool IsDBNull (int ordinal) {
583 ValidateState("IsDBNull");
586 return (currentDataRow.IsNull(ordinal));
588 catch(IndexOutOfRangeException e) { // thrown by DataColumnCollection
589 ExceptionBuilder.TraceExceptionWithoutRethrow(e);
590 throw ExceptionBuilder.ArgumentOutOfRange("ordinal");
595 override public IEnumerator GetEnumerator() {
596 ValidateOpen("GetEnumerator");
597 return new DbEnumerator((IDataReader)this);
600 static internal DataTable GetSchemaTableFromDataTable(DataTable table) {
602 throw ExceptionBuilder.ArgumentNull("DataTable");
605 DataTable tempSchemaTable = new DataTable("SchemaTable");
606 tempSchemaTable.Locale = System.Globalization.CultureInfo.InvariantCulture;
608 DataColumn ColumnName = new DataColumn(SchemaTableColumn.ColumnName, typeof(System.String));
609 DataColumn ColumnOrdinal = new DataColumn(SchemaTableColumn.ColumnOrdinal, typeof(System.Int32));
610 DataColumn ColumnSize = new DataColumn(SchemaTableColumn.ColumnSize, typeof(System.Int32));
611 DataColumn NumericPrecision = new DataColumn(SchemaTableColumn.NumericPrecision, typeof(System.Int16));
612 DataColumn NumericScale = new DataColumn(SchemaTableColumn.NumericScale, typeof(System.Int16));
613 DataColumn DataType = new DataColumn(SchemaTableColumn.DataType, typeof(System.Type));
614 DataColumn ProviderType = new DataColumn(SchemaTableColumn.ProviderType, typeof(System.Int32));
615 DataColumn IsLong = new DataColumn(SchemaTableColumn.IsLong, typeof(System.Boolean));
616 DataColumn AllowDBNull = new DataColumn(SchemaTableColumn.AllowDBNull, typeof(System.Boolean));
617 DataColumn IsReadOnly = new DataColumn(SchemaTableOptionalColumn.IsReadOnly, typeof(System.Boolean));
618 DataColumn IsRowVersion = new DataColumn(SchemaTableOptionalColumn.IsRowVersion, typeof(System.Boolean));
619 DataColumn IsUnique = new DataColumn(SchemaTableColumn.IsUnique, typeof(System.Boolean));
620 DataColumn IsKeyColumn = new DataColumn(SchemaTableColumn.IsKey, typeof(System.Boolean));
621 DataColumn IsAutoIncrement = new DataColumn(SchemaTableOptionalColumn.IsAutoIncrement, typeof(System.Boolean));
622 DataColumn BaseSchemaName = new DataColumn(SchemaTableColumn.BaseSchemaName, typeof(System.String));
623 DataColumn BaseCatalogName = new DataColumn(SchemaTableOptionalColumn.BaseCatalogName, typeof(System.String));
624 DataColumn BaseTableName = new DataColumn(SchemaTableColumn.BaseTableName, typeof(System.String));
625 DataColumn BaseColumnName = new DataColumn(SchemaTableColumn.BaseColumnName, typeof(System.String));
626 DataColumn AutoIncrementSeed = new DataColumn(SchemaTableOptionalColumn.AutoIncrementSeed, typeof(System.Int64));
627 DataColumn AutoIncrementStep = new DataColumn(SchemaTableOptionalColumn.AutoIncrementStep, typeof(System.Int64));
628 DataColumn DefaultValue = new DataColumn(SchemaTableOptionalColumn.DefaultValue, typeof(System.Object));
629 DataColumn Expression = new DataColumn(SchemaTableOptionalColumn.Expression, typeof(System.String));
630 DataColumn ColumnMapping = new DataColumn(SchemaTableOptionalColumn.ColumnMapping, typeof(System.Data.MappingType));
631 DataColumn BaseTableNamespace = new DataColumn(SchemaTableOptionalColumn.BaseTableNamespace, typeof(System.String));
632 DataColumn BaseColumnNamespace = new DataColumn(SchemaTableOptionalColumn.BaseColumnNamespace, typeof(System.String));
634 ColumnSize.DefaultValue = -1;
636 if (table.DataSet != null)
637 BaseCatalogName.DefaultValue = table.DataSet.DataSetName;
639 BaseTableName.DefaultValue = table.TableName;
640 BaseTableNamespace.DefaultValue = table.Namespace;
641 IsRowVersion.DefaultValue = false;
642 IsLong.DefaultValue = false;
643 IsReadOnly.DefaultValue = false;
644 IsKeyColumn.DefaultValue = false;
645 IsAutoIncrement.DefaultValue = false;
646 AutoIncrementSeed.DefaultValue = 0;
647 AutoIncrementStep.DefaultValue = 1;
650 tempSchemaTable.Columns.Add(ColumnName);
651 tempSchemaTable.Columns.Add(ColumnOrdinal);
652 tempSchemaTable.Columns.Add(ColumnSize);
653 tempSchemaTable.Columns.Add(NumericPrecision);
654 tempSchemaTable.Columns.Add(NumericScale);
655 tempSchemaTable.Columns.Add(DataType);
656 tempSchemaTable.Columns.Add(ProviderType);
657 tempSchemaTable.Columns.Add(IsLong);
658 tempSchemaTable.Columns.Add(AllowDBNull);
659 tempSchemaTable.Columns.Add(IsReadOnly);
660 tempSchemaTable.Columns.Add(IsRowVersion);
661 tempSchemaTable.Columns.Add(IsUnique);
662 tempSchemaTable.Columns.Add(IsKeyColumn);
663 tempSchemaTable.Columns.Add(IsAutoIncrement);
664 tempSchemaTable.Columns.Add(BaseCatalogName);
665 tempSchemaTable.Columns.Add(BaseSchemaName);
666 // specific to datatablereader
667 tempSchemaTable.Columns.Add(BaseTableName);
668 tempSchemaTable.Columns.Add(BaseColumnName);
669 tempSchemaTable.Columns.Add(AutoIncrementSeed);
670 tempSchemaTable.Columns.Add(AutoIncrementStep);
671 tempSchemaTable.Columns.Add(DefaultValue);
672 tempSchemaTable.Columns.Add(Expression);
673 tempSchemaTable.Columns.Add(ColumnMapping);
674 tempSchemaTable.Columns.Add(BaseTableNamespace);
675 tempSchemaTable.Columns.Add(BaseColumnNamespace);
677 foreach (DataColumn dc in table.Columns) {
678 DataRow dr = tempSchemaTable.NewRow();
680 dr[ColumnName] = dc.ColumnName;
681 dr[ColumnOrdinal] = dc.Ordinal;
682 dr[DataType] = dc.DataType;
684 if (dc.DataType == typeof(string)) {
685 dr[ColumnSize] = dc.MaxLength;
688 dr[AllowDBNull] = dc.AllowDBNull;
689 dr[IsReadOnly] = dc.ReadOnly;
690 dr[IsUnique] = dc.Unique;
692 if (dc.AutoIncrement) {
693 dr[IsAutoIncrement] = true;
694 dr[AutoIncrementSeed] = dc.AutoIncrementSeed;
695 dr[AutoIncrementStep] = dc.AutoIncrementStep;
698 if (dc.DefaultValue != DBNull.Value)
699 dr[DefaultValue] = dc.DefaultValue;
701 if (dc.Expression.Length != 0) {
702 bool hasExternalDependency = false;
703 DataColumn[] dependency = dc.DataExpression.GetDependency();
704 for (int j = 0; j < dependency.Length; j++) {
705 if (dependency[j].Table != table) {
706 hasExternalDependency = true;
710 if (!hasExternalDependency)
711 dr[Expression] = dc.Expression;
714 dr[ColumnMapping] = dc.ColumnMapping;
715 dr[BaseColumnName] = dc.ColumnName;
716 dr[BaseColumnNamespace] = dc.Namespace;
718 tempSchemaTable.Rows.Add(dr);
721 foreach(DataColumn key in table.PrimaryKey) {
722 tempSchemaTable.Rows[key.Ordinal][IsKeyColumn] = true;
726 tempSchemaTable.AcceptChanges();
728 return tempSchemaTable;
731 private void ValidateOpen(string caller) {
733 throw ADP.DataReaderClosed(caller);
736 private void ValidateReader() {
738 throw ExceptionBuilder.InvalidDataTableReader(currentDataTable.TableName);
740 if (IsSchemaChanged) {
741 throw ExceptionBuilder.DataTableReaderSchemaIsInvalid(currentDataTable.TableName); // may be we can use better error message!
746 private void ValidateState(string caller) {
747 ValidateOpen(caller);
749 throw ExceptionBuilder.EmptyDataTableReader(currentDataTable.TableName);
751 // see if without any event raising, if our curent row has some changes!if so reader is invalid.
752 if ((currentDataRow == null) || (currentDataTable == null) ) {//|| (currentDataRow != currentDataTable.Rows[rowCounter])) do we need thios check!
753 ReaderIsInvalid = true;
754 throw ExceptionBuilder.InvalidDataTableReader(currentDataTable.TableName);
756 //See if without any event raing, if our rows are deleted, or removed! Reader is not invalid, user should be able to read and reach goo row WebData98325
757 if ((currentDataRow.RowState == DataRowState.Deleted) || (currentDataRow.RowState == DataRowState.Detached) ||currentRowRemoved)
758 throw ExceptionBuilder.InvalidCurrentRowInDataTableReader();
759 // user may have called clear (which removes the rows without raing event) or deleted part of rows without raising event!if so reader is invalid.
760 if (0 > rowCounter ||currentDataTable.Rows.Count <= rowCounter) {
761 ReaderIsInvalid = true;
762 throw ExceptionBuilder.InvalidDataTableReader(currentDataTable.TableName);
769 private void ValidateRow(Int32 rowPosition) {
771 throw ExceptionBuilder.InvalidDataTableReader(currentDataTable.TableName);
773 if (0 > rowPosition ||currentDataTable.Rows.Count <= rowPosition) {
774 ReaderIsInvalid = true;
775 throw ExceptionBuilder.InvalidDataTableReader(currentDataTable.TableName);
779 // Event Call backs from DataTableReaderListener, will invoke these methods
780 internal void SchemaChanged() {
781 IsSchemaChanged = true;
783 internal void DataTableCleared() {
789 currentRowRemoved = true;
792 internal void DataChanged(DataRowChangeEventArgs args ) {
793 if ((!started) ||(rowCounter == -1 && !tableCleared))
795 /* if (rowCounter == -1 && tableCleared && args.Action == DataRowAction.Add) {
796 tableCleared = false;
800 switch (args.Action) {
801 case DataRowAction.Add:
802 ValidateRow(rowCounter + 1);
803 /* if (tableCleared) {
804 tableCleared = false;
806 currentDataRow = currentDataTable.Rows[rowCounter];
807 currentRowRemoved = false;
811 if (currentDataRow == currentDataTable.Rows[rowCounter + 1]) { // check if we moved one position up
812 rowCounter++; // if so, refresh the datarow and fix the counter
815 case DataRowAction.Delete: // delete
816 case DataRowAction.Rollback:// rejectchanges
817 case DataRowAction.Commit: // acceptchanges
818 if ( args.Row.RowState == DataRowState.Detached ) {
819 if (args.Row != currentDataRow) {
820 if (rowCounter == 0) // if I am at first row and no previous row exist,NOOP
822 ValidateRow(rowCounter -1);
823 if (currentDataRow == currentDataTable.Rows[rowCounter - 1]) { // one of previous rows is detached, collection size is changed!
827 else { // we are proccessing current datarow
828 currentRowRemoved = true;
829 if (rowCounter > 0) { // go back one row, no matter what the state is
831 currentDataRow = currentDataTable.Rows[rowCounter];
833 else { // we are on 0th row, so reset data to initial state!
835 currentDataRow = null;