private SchemaMapping FillMapping(DataSet dataset, DataTable datatable, string srcTable, DataReaderContainer dataReader, int schemaCount, DataColumn parentChapterColumn, object parentChapterValue) { SchemaMapping mapping = null; if (_hasFillErrorHandler) { try { // only try-catch if a FillErrorEventHandler is registered so that // in the default case we get the full callstack from users mapping = FillMappingInternal(dataset, datatable, srcTable, dataReader, schemaCount, parentChapterColumn, parentChapterValue); } catch (Exception e) { // if (!ADP.IsCatchableExceptionType(e)) { throw; } ADP.TraceExceptionForCapture(e); OnFillErrorHandler(e, null, null); } } else { mapping = FillMappingInternal(dataset, datatable, srcTable, dataReader, schemaCount, parentChapterColumn, parentChapterValue); } return(mapping); }
private int FillLoadDataRow(SchemaMapping mapping) { int rowsAddedToDataSet = 0; DataReaderContainer dataReader = mapping.DataReader; if (_hasFillErrorHandler) { while (dataReader.Read()) { // read remaining rows of first and subsequent resultsets try { // only try-catch if a FillErrorEventHandler is registered so that // in the default case we get the full callstack from users mapping.LoadDataRowWithClear(); rowsAddedToDataSet++; } catch (Exception e) when(ADP.IsCatchableExceptionType(e)) { ADP.TraceExceptionForCapture(e); OnFillErrorHandler(e, mapping.DataTable, mapping.DataValues); } } } else { while (dataReader.Read()) { // read remaining rows of first and subsequent resultset mapping.LoadDataRow(); rowsAddedToDataSet++; } } return(rowsAddedToDataSet); }
internal int FillFromReader(DataSet dataset, DataTable datatable, string srcTable, DataReaderContainer dataReader, int startRecord, int maxRecords, DataColumn parentChapterColumn, object parentChapterValue) { int rowsAddedToDataSet = 0; int schemaCount = 0; do { AssertReaderHandleFieldCount(dataReader); if (0 >= dataReader.FieldCount) { continue; // loop to next result } SchemaMapping mapping = FillMapping(dataset, datatable, srcTable, dataReader, schemaCount, parentChapterColumn, parentChapterValue); schemaCount++; // don't increment if no SchemaTable ( a non-row returning result ) AssertSchemaMapping(mapping); if (null == mapping) { continue; // loop to next result } if (null == mapping.DataValues) { continue; // loop to next result } if (null == mapping.DataTable) { continue; // loop to next result } mapping.DataTable.BeginLoadData(); try { // startRecord and maxRecords only apply to the first resultset if ((1 == schemaCount) && ((0 < startRecord) || (0 < maxRecords))) { rowsAddedToDataSet = FillLoadDataRowChunk(mapping, startRecord, maxRecords); } else { int count = FillLoadDataRow(mapping); if (1 == schemaCount) // MDAC 71347 // only return LoadDataRow count for first resultset // not secondary or chaptered results { rowsAddedToDataSet = count; } } } finally { mapping.DataTable.EndLoadData(); } if (null != datatable) { break; // do not read remaining results in single DataTable case } } while (FillNextResult(dataReader)); return(rowsAddedToDataSet); }
private int FillLoadDataRow(SchemaMapping mapping) { int num = 0; DataReaderContainer dataReader = mapping.DataReader; if (!this._hasFillErrorHandler) { while (dataReader.Read()) { mapping.LoadDataRow(); num++; } return(num); } while (dataReader.Read()) { try { mapping.LoadDataRowWithClear(); num++; continue; } catch (Exception exception) { if (!ADP.IsCatchableExceptionType(exception)) { throw; } ADP.TraceExceptionForCapture(exception); this.OnFillErrorHandler(exception, mapping.DataTable, mapping.DataValues); continue; } } return(num); }
private void AssertSchemaMapping(SchemaMapping mapping) { #if DEBUG if (_debugHookNonEmptySelectCommand) { Debug.Assert(mapping != null && mapping.DataValues != null && mapping.DataTable != null, "Debug hook specifies that non-empty results are not expected"); } #endif }
internal object FillSchemaFromReader(DataSet dataset, DataTable datatable, SchemaType schemaType, string srcTable, IDataReader dataReader) { DataTable[] dataTables = null; int schemaCount = 0; do { DataReaderContainer readerHandler = DataReaderContainer.Create(dataReader, ReturnProviderSpecificTypes); AssertReaderHandleFieldCount(readerHandler); if (0 >= readerHandler.FieldCount) { continue; } string tmp = null; if (null != dataset) { tmp = DataAdapter.GetSourceTableName(srcTable, schemaCount); schemaCount++; // don't increment if no SchemaTable ( a non-row returning result ) } SchemaMapping mapping = new SchemaMapping(this, dataset, datatable, readerHandler, true, schemaType, tmp, false, null, null); if (null != datatable) { // do not read remaining results in single DataTable case return(mapping.DataTable); } else if (null != mapping.DataTable) { if (null == dataTables) { dataTables = new DataTable[1] { mapping.DataTable }; } else { dataTables = DataAdapter.AddDataTableToArray(dataTables, mapping.DataTable); } } } while (dataReader.NextResult()); // FillSchema does not capture errors for FillError event object value = dataTables; if ((null == value) && (null == datatable)) { value = Array.Empty <DataTable>(); } return(value); // null if datatable had no results }
private int FillLoadDataRowChunk(SchemaMapping mapping, int startRecord, int maxRecords) { DataReaderContainer dataReader = mapping.DataReader; while (0 < startRecord) { if (!dataReader.Read()) { // there are no more rows on first resultset return(0); } --startRecord; } int rowsAddedToDataSet = 0; if (0 < maxRecords) { while ((rowsAddedToDataSet < maxRecords) && dataReader.Read()) { if (_hasFillErrorHandler) { try { mapping.LoadDataRowWithClear(); rowsAddedToDataSet++; } catch (Exception e) { // if (!ADP.IsCatchableExceptionType(e)) { throw; } ADP.TraceExceptionForCapture(e); OnFillErrorHandler(e, mapping.DataTable, mapping.DataValues); } } else { mapping.LoadDataRow(); rowsAddedToDataSet++; } } // skip remaining rows of the first resultset } else { rowsAddedToDataSet = FillLoadDataRow(mapping); } return(rowsAddedToDataSet); }
private int FillLoadDataRowChunk(SchemaMapping mapping, int startRecord, int maxRecords) { DataReaderContainer dataReader = mapping.DataReader; while (0 < startRecord) { if (!dataReader.Read()) { return(0); } startRecord--; } int num = 0; if (0 >= maxRecords) { return(this.FillLoadDataRow(mapping)); } while ((num < maxRecords) && dataReader.Read()) { if (this._hasFillErrorHandler) { try { mapping.LoadDataRowWithClear(); num++; } catch (Exception exception) { if (!ADP.IsCatchableExceptionType(exception)) { throw; } ADP.TraceExceptionForCapture(exception); this.OnFillErrorHandler(exception, mapping.DataTable, mapping.DataValues); } } else { mapping.LoadDataRow(); num++; } } return(num); }
internal object FillSchemaFromReader(DataSet dataset, DataTable datatable, SchemaType schemaType, string srcTable, IDataReader dataReader) { DataTable[] tables = null; int index = 0; do { DataReaderContainer container = DataReaderContainer.Create(dataReader, this.ReturnProviderSpecificTypes); if (0 < container.FieldCount) { string sourceTableName = null; if (dataset != null) { sourceTableName = GetSourceTableName(srcTable, index); index++; } SchemaMapping mapping = new SchemaMapping(this, dataset, datatable, container, true, schemaType, sourceTableName, false, null, null); if (datatable != null) { return(mapping.DataTable); } if (mapping.DataTable != null) { if (tables == null) { tables = new DataTable[] { mapping.DataTable }; } else { tables = AddDataTableToArray(tables, mapping.DataTable); } } } }while (dataReader.NextResult()); object obj2 = tables; if ((obj2 == null) && (datatable == null)) { obj2 = new DataTable[0]; } return(obj2); }
internal int FillFromReader(DataSet dataset, DataTable datatable, string srcTable, DataReaderContainer dataReader, int startRecord, int maxRecords, DataColumn parentChapterColumn, object parentChapterValue) { int num2 = 0; int schemaCount = 0; do { if (0 < dataReader.FieldCount) { SchemaMapping mapping = this.FillMapping(dataset, datatable, srcTable, dataReader, schemaCount, parentChapterColumn, parentChapterValue); schemaCount++; if (((mapping != null) && (mapping.DataValues != null)) && (mapping.DataTable != null)) { mapping.DataTable.BeginLoadData(); try { if ((1 == schemaCount) && ((0 < startRecord) || (0 < maxRecords))) { num2 = this.FillLoadDataRowChunk(mapping, startRecord, maxRecords); } else { int num3 = this.FillLoadDataRow(mapping); if (1 == schemaCount) { num2 = num3; } } } finally { mapping.DataTable.EndLoadData(); } if (datatable != null) { return(num2); } } } }while (this.FillNextResult(dataReader)); return(num2); }
private SchemaMapping FillMapping(DataSet dataset, DataTable datatable, string srcTable, DataReaderContainer dataReader, int schemaCount, DataColumn parentChapterColumn, object parentChapterValue) { SchemaMapping mapping = null; if (this._hasFillErrorHandler) { try { mapping = this.FillMappingInternal(dataset, datatable, srcTable, dataReader, schemaCount, parentChapterColumn, parentChapterValue); } catch (Exception exception) { if (!ADP.IsCatchableExceptionType(exception)) { throw; } ADP.TraceExceptionForCapture(exception); this.OnFillErrorHandler(exception, null, null); } return(mapping); } return(this.FillMappingInternal(dataset, datatable, srcTable, dataReader, schemaCount, parentChapterColumn, parentChapterValue)); }