Пример #1
0
 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;
 }
Пример #2
0
        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[] columnNameArray = new string[dataReader.FieldCount];
     for (int i = 0; i < columnNameArray.Length; i++)
     {
         columnNameArray[i] = dataReader.GetName(i);
     }
     ADP.BuildSchemaTableInfoTableNames(columnNameArray);
     return columnNameArray;
 }
        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);
                }
            }
        }
Пример #5
0
 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;
 }
Пример #6
0
 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;
 }
Пример #7
0
        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;
        }
Пример #8
0
 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);
 }
Пример #9
0
        void AssertReaderHandleFieldCount(DataReaderContainer readerHandler) {
#if DEBUG
            Debug.Assert(!_debugHookNonEmptySelectCommand || readerHandler.FieldCount > 0, "Scenario expects non-empty results but no fields reported by reader");
#endif
        }
 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;
 }