private static string[] GenerateFieldNames(DataReaderContainer dataReader)
 {
     string[] columnNameArray = new string[dataReader.FieldCount];
     for (int i = 0; i < columnNameArray.Length; i++)
     {
         columnNameArray[i] = dataReader.GetName(i);
     }
     ADP.BuildSchemaTableInfoTableNames(columnNameArray);
     return(columnNameArray);
 }
        internal int LoadDataRowChapters(DataRow dataRow)
        {
            int num2   = 0;
            int length = this._chapterMap.Length;

            for (int i = 0; i < length; i++)
            {
                if (this._chapterMap[i])
                {
                    object obj2 = this._readerDataValues[i];
                    if ((obj2 != null) && !Convert.IsDBNull(obj2))
                    {
                        this._readerDataValues[i] = null;
                        using (IDataReader reader = (IDataReader)obj2)
                        {
                            if (!reader.IsClosed)
                            {
                                DataColumn column;
                                object     obj3;
                                if (this._indexMap == null)
                                {
                                    column = this._dataTable.Columns[i];
                                    obj3   = dataRow[column];
                                }
                                else
                                {
                                    column = this._dataTable.Columns[this._indexMap[i]];
                                    obj3   = dataRow[column];
                                }
                                string srcTable = this._tableMapping.SourceTable + this._fieldNames[i];
                                DataReaderContainer dataReader = DataReaderContainer.Create(reader, this._dataReader.ReturnProviderSpecificTypes);
                                num2 += this._adapter.FillFromReader(this._dataSet, null, srcTable, dataReader, 0, 0, column, obj3);
                            }
                        }
                    }
                }
            }
            return(num2);
        }
        internal SchemaMapping(DataAdapter adapter, DataSet dataset, DataTable datatable, DataReaderContainer dataReader, bool keyInfo,
                                    SchemaType schemaType, string sourceTableName, bool gettingData,
                                    DataColumn parentChapterColumn, object parentChapterValue) {
            Debug.Assert(null != adapter, "adapter");
            Debug.Assert(null != dataReader, "dataReader");
            Debug.Assert(0 < dataReader.FieldCount, "FieldCount");
            Debug.Assert(null != dataset || null != datatable, "SchemaMapping - null dataSet");
            Debug.Assert(SchemaType.Mapped == schemaType || SchemaType.Source == schemaType, "SetupSchema - invalid schemaType");

            _dataSet = dataset;     // setting DataSet implies chapters are supported
            _dataTable = datatable; // setting only DataTable, not DataSet implies chapters are not supported
            _adapter = adapter;
            _dataReader = dataReader;

            if (keyInfo) {
                _schemaTable = dataReader.GetSchemaTable();
            }

            if (adapter.ShouldSerializeFillLoadOption()) {
                _loadOption = adapter.FillLoadOption;
            }
            else if (adapter.AcceptChangesDuringFill) {
                _loadOption = (LoadOption)4; // true
            }
            else {
                _loadOption = (LoadOption)5; //false
            }

            MissingMappingAction mappingAction;
            MissingSchemaAction schemaAction;
            if (SchemaType.Mapped == schemaType) {
                mappingAction = _adapter.MissingMappingAction;
                schemaAction = _adapter.MissingSchemaAction;
                if (!ADP.IsEmpty(sourceTableName)) { // MDAC 66034
                    _tableMapping = _adapter.GetTableMappingBySchemaAction(sourceTableName, sourceTableName, mappingAction);
                }
                else if (null != _dataTable) {
                    int index = _adapter.IndexOfDataSetTable(_dataTable.TableName);
                    if (-1 != index) {
                        _tableMapping = _adapter.TableMappings[index];
                    }
                    else {
                        switch (mappingAction) {
                        case MissingMappingAction.Passthrough:
                            _tableMapping = new DataTableMapping(_dataTable.TableName, _dataTable.TableName);
                            break;
                        case MissingMappingAction.Ignore:
                            _tableMapping = null;
                            break;
                        case MissingMappingAction.Error:
                            throw ADP.MissingTableMappingDestination(_dataTable.TableName);
                        default:
                            throw ADP.InvalidMissingMappingAction(mappingAction);
                        }
                    }
                }
            }
            else if (SchemaType.Source == schemaType) {
                mappingAction = System.Data.MissingMappingAction.Passthrough;
                schemaAction = Data.MissingSchemaAction.Add;
                if (!ADP.IsEmpty(sourceTableName)) { // MDAC 66034
                    _tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction(null, sourceTableName, sourceTableName, mappingAction);
                }
                else if (null != _dataTable) {
                    int index = _adapter.IndexOfDataSetTable(_dataTable.TableName); // MDAC 66034
                    if (-1 != index) {
                        _tableMapping = _adapter.TableMappings[index];
                    }
                    else {
                        _tableMapping = new DataTableMapping(_dataTable.TableName, _dataTable.TableName);
                    }
                }
            }
            else {
                throw ADP.InvalidSchemaType(schemaType);
            }

            if (null != _tableMapping) {
                if (null == _dataTable) {
                    _dataTable = _tableMapping.GetDataTableBySchemaAction(_dataSet, schemaAction);
                }
                if (null != _dataTable) {
                    _fieldNames = GenerateFieldNames(dataReader);

                    if (null == _schemaTable) {
                        _readerDataValues = SetupSchemaWithoutKeyInfo(mappingAction, schemaAction, gettingData, parentChapterColumn, parentChapterValue);
                    }
                    else {
                        _readerDataValues = SetupSchemaWithKeyInfo(mappingAction, schemaAction, gettingData, parentChapterColumn, parentChapterValue);
                    }
                }
                // else (null == _dataTable) which means ignore (mapped to nothing)
            }
        }
 private static string[] GenerateFieldNames(DataReaderContainer dataReader) {
     string[] fieldNames = new string[dataReader.FieldCount];
     for(int i = 0; i < fieldNames.Length; ++i) {
         fieldNames[i] = dataReader.GetName(i);
     }
     ADP.BuildSchemaTableInfoTableNames(fieldNames);
     return fieldNames;
 }
        internal SchemaMapping(DataAdapter adapter, DataSet dataset, System.Data.DataTable datatable, DataReaderContainer dataReader, bool keyInfo, SchemaType schemaType, string sourceTableName, bool gettingData, DataColumn parentChapterColumn, object parentChapterValue)
        {
            MissingMappingAction missingMappingAction;
            MissingSchemaAction missingSchemaAction;
            this._dataSet = dataset;
            this._dataTable = datatable;
            this._adapter = adapter;
            this._dataReader = dataReader;
            if (keyInfo)
            {
                this._schemaTable = dataReader.GetSchemaTable();
            }
            if (adapter.ShouldSerializeFillLoadOption())
            {
                this._loadOption = adapter.FillLoadOption;
            }
            else if (adapter.AcceptChangesDuringFill)
            {
                this._loadOption = (LoadOption) 4;
            }
            else
            {
                this._loadOption = (LoadOption) 5;
            }
            if (SchemaType.Mapped == schemaType)
            {
                missingMappingAction = this._adapter.MissingMappingAction;
                missingSchemaAction = this._adapter.MissingSchemaAction;
                if (ADP.IsEmpty(sourceTableName))
                {
                    if (this._dataTable != null)
                    {
                        int num2 = this._adapter.IndexOfDataSetTable(this._dataTable.TableName);
                        if (-1 == num2)
                        {
                            switch (missingMappingAction)
                            {
                                case MissingMappingAction.Passthrough:
                                    this._tableMapping = new DataTableMapping(this._dataTable.TableName, this._dataTable.TableName);
                                    goto Label_01DB;

                                case MissingMappingAction.Ignore:
                                    this._tableMapping = null;
                                    goto Label_01DB;

                                case MissingMappingAction.Error:
                                    throw ADP.MissingTableMappingDestination(this._dataTable.TableName);
                            }
                            throw ADP.InvalidMissingMappingAction(missingMappingAction);
                        }
                        this._tableMapping = this._adapter.TableMappings[num2];
                    }
                }
                else
                {
                    this._tableMapping = this._adapter.GetTableMappingBySchemaAction(sourceTableName, sourceTableName, missingMappingAction);
                }
            }
            else
            {
                if (SchemaType.Source != schemaType)
                {
                    throw ADP.InvalidSchemaType(schemaType);
                }
                missingMappingAction = MissingMappingAction.Passthrough;
                missingSchemaAction = MissingSchemaAction.Add;
                if (!ADP.IsEmpty(sourceTableName))
                {
                    this._tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction(null, sourceTableName, sourceTableName, missingMappingAction);
                }
                else if (this._dataTable != null)
                {
                    int num = this._adapter.IndexOfDataSetTable(this._dataTable.TableName);
                    if (-1 != num)
                    {
                        this._tableMapping = this._adapter.TableMappings[num];
                    }
                    else
                    {
                        this._tableMapping = new DataTableMapping(this._dataTable.TableName, this._dataTable.TableName);
                    }
                }
            }
        Label_01DB:
            if (this._tableMapping != null)
            {
                if (this._dataTable == null)
                {
                    this._dataTable = this._tableMapping.GetDataTableBySchemaAction(this._dataSet, missingSchemaAction);
                }
                if (this._dataTable != null)
                {
                    this._fieldNames = GenerateFieldNames(dataReader);
                    if (this._schemaTable == null)
                    {
                        this._readerDataValues = this.SetupSchemaWithoutKeyInfo(missingMappingAction, missingSchemaAction, gettingData, parentChapterColumn, parentChapterValue);
                        return;
                    }
                    this._readerDataValues = this.SetupSchemaWithKeyInfo(missingMappingAction, missingSchemaAction, gettingData, parentChapterColumn, parentChapterValue);
                }
            }
        }
 private static string[] GenerateFieldNames(DataReaderContainer dataReader)
 {
     string[] columnNameArray = new string[dataReader.FieldCount];
     for (int i = 0; i < columnNameArray.Length; i++)
     {
         columnNameArray[i] = dataReader.GetName(i);
     }
     ADP.BuildSchemaTableInfoTableNames(columnNameArray);
     return columnNameArray;
 }
 private bool FillNextResult(DataReaderContainer dataReader) {
     bool result = true;
     if (_hasFillErrorHandler) {
         try {
             // only try-catch if a FillErrorEventHandler is registered so that
             // in the default case we get the full callstack from users
             result = dataReader.NextResult();
         }
         catch(Exception e) {
             // 
             if (!ADP.IsCatchableExceptionType(e)) {
                 throw;
             }
             ADP.TraceExceptionForCapture(e);
             OnFillErrorHandler(e, null, null);
         }
     }
     else {
         result = dataReader.NextResult();
     }
     return result;
 }
 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 SchemaMapping FillMappingInternal(DataSet dataset, DataTable datatable, string srcTable, DataReaderContainer dataReader, int schemaCount, DataColumn parentChapterColumn, object parentChapterValue) {
     bool withKeyInfo = (Data.MissingSchemaAction.AddWithKey == MissingSchemaAction);
     string tmp = null;
     if (null != dataset) {
         tmp = DataAdapter.GetSourceTableName(srcTable, schemaCount);
     }
     return new SchemaMapping(this, dataset, datatable, dataReader, withKeyInfo, SchemaType.Mapped, tmp, true, parentChapterColumn, parentChapterValue);
 }
        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;
        }
        void AssertReaderHandleFieldCount(DataReaderContainer readerHandler) {
#if DEBUG
            Debug.Assert(!_debugHookNonEmptySelectCommand || readerHandler.FieldCount > 0, "Scenario expects non-empty results but no fields reported by reader");
#endif
        }
        internal SchemaMapping(DataAdapter adapter, DataSet dataset, System.Data.DataTable datatable, DataReaderContainer dataReader, bool keyInfo, SchemaType schemaType, string sourceTableName, bool gettingData, DataColumn parentChapterColumn, object parentChapterValue)
        {
            MissingMappingAction missingMappingAction;
            MissingSchemaAction  missingSchemaAction;

            this._dataSet    = dataset;
            this._dataTable  = datatable;
            this._adapter    = adapter;
            this._dataReader = dataReader;
            if (keyInfo)
            {
                this._schemaTable = dataReader.GetSchemaTable();
            }
            if (adapter.ShouldSerializeFillLoadOption())
            {
                this._loadOption = adapter.FillLoadOption;
            }
            else if (adapter.AcceptChangesDuringFill)
            {
                this._loadOption = (LoadOption)4;
            }
            else
            {
                this._loadOption = (LoadOption)5;
            }
            if (SchemaType.Mapped == schemaType)
            {
                missingMappingAction = this._adapter.MissingMappingAction;
                missingSchemaAction  = this._adapter.MissingSchemaAction;
                if (ADP.IsEmpty(sourceTableName))
                {
                    if (this._dataTable != null)
                    {
                        int num2 = this._adapter.IndexOfDataSetTable(this._dataTable.TableName);
                        if (-1 == num2)
                        {
                            switch (missingMappingAction)
                            {
                            case MissingMappingAction.Passthrough:
                                this._tableMapping = new DataTableMapping(this._dataTable.TableName, this._dataTable.TableName);
                                goto Label_01DB;

                            case MissingMappingAction.Ignore:
                                this._tableMapping = null;
                                goto Label_01DB;

                            case MissingMappingAction.Error:
                                throw ADP.MissingTableMappingDestination(this._dataTable.TableName);
                            }
                            throw ADP.InvalidMissingMappingAction(missingMappingAction);
                        }
                        this._tableMapping = this._adapter.TableMappings[num2];
                    }
                }
                else
                {
                    this._tableMapping = this._adapter.GetTableMappingBySchemaAction(sourceTableName, sourceTableName, missingMappingAction);
                }
            }
            else
            {
                if (SchemaType.Source != schemaType)
                {
                    throw ADP.InvalidSchemaType(schemaType);
                }
                missingMappingAction = MissingMappingAction.Passthrough;
                missingSchemaAction  = MissingSchemaAction.Add;
                if (!ADP.IsEmpty(sourceTableName))
                {
                    this._tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction(null, sourceTableName, sourceTableName, missingMappingAction);
                }
                else if (this._dataTable != null)
                {
                    int num = this._adapter.IndexOfDataSetTable(this._dataTable.TableName);
                    if (-1 != num)
                    {
                        this._tableMapping = this._adapter.TableMappings[num];
                    }
                    else
                    {
                        this._tableMapping = new DataTableMapping(this._dataTable.TableName, this._dataTable.TableName);
                    }
                }
            }
Label_01DB:
            if (this._tableMapping != null)
            {
                if (this._dataTable == null)
                {
                    this._dataTable = this._tableMapping.GetDataTableBySchemaAction(this._dataSet, missingSchemaAction);
                }
                if (this._dataTable != null)
                {
                    this._fieldNames = GenerateFieldNames(dataReader);
                    if (this._schemaTable == null)
                    {
                        this._readerDataValues = this.SetupSchemaWithoutKeyInfo(missingMappingAction, missingSchemaAction, gettingData, parentChapterColumn, parentChapterValue);
                        return;
                    }
                    this._readerDataValues = this.SetupSchemaWithKeyInfo(missingMappingAction, missingSchemaAction, gettingData, parentChapterColumn, parentChapterValue);
                }
            }
        }
 private bool FillNextResult(DataReaderContainer dataReader)
 {
     bool flag = true;
     if (this._hasFillErrorHandler)
     {
         try
         {
             flag = dataReader.NextResult();
         }
         catch (Exception exception)
         {
             if (!ADP.IsCatchableExceptionType(exception))
             {
                 throw;
             }
             ADP.TraceExceptionForCapture(exception);
             this.OnFillErrorHandler(exception, null, null);
         }
         return flag;
     }
     return dataReader.NextResult();
 }
 private SchemaMapping FillMappingInternal(DataSet dataset, DataTable datatable, string srcTable, DataReaderContainer dataReader, int schemaCount, DataColumn parentChapterColumn, object parentChapterValue)
 {
     bool keyInfo = System.Data.MissingSchemaAction.AddWithKey == this.MissingSchemaAction;
     string sourceTableName = null;
     if (dataset != null)
     {
         sourceTableName = GetSourceTableName(srcTable, schemaCount);
     }
     return new SchemaMapping(this, dataset, datatable, dataReader, keyInfo, SchemaType.Mapped, sourceTableName, true, parentChapterColumn, parentChapterValue);
 }
 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);
 }
 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;
 }