Exemplo n.º 1
0
        private async Task <bool> FillNextResultAsync(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 = await dataReader.NextResultAsync();
                }
                catch (Exception e)
                {
                    //
                    if (!ADP.IsCatchableExceptionType(e))
                    {
                        throw;
                    }
                    ADP.TraceExceptionForCapture(e);
                    OnFillErrorHandler(e, null, null);
                }
            }
            else
            {
                result = await dataReader.NextResultAsync();
            }
            return(result);
        }
Exemplo n.º 2
0
        private async Task <int> FillLoadDataRowChunkAsync(SchemaMapping mapping, int startRecord, int maxRecords)
        {
            DataReaderContainer dataReader = mapping.DataReader;

            while (0 < startRecord)
            {
                if (!await dataReader.ReadAsync())
                {
                    // there are no more rows on first resultset
                    return(0);
                }
                --startRecord;
            }

            int rowsAddedToDataSet = 0;

            if (0 < maxRecords)
            {
                while ((rowsAddedToDataSet < maxRecords) && await dataReader.ReadAsync())
                {
                    if (_hasFillErrorHandler)
                    {
                        try
                        {
                            await mapping.LoadDataRowWithClear();

                            rowsAddedToDataSet++;
                        }
                        catch (Exception e)
                        {
                            //
                            if (!ADP.IsCatchableExceptionType(e))
                            {
                                throw;
                            }
                            ADP.TraceExceptionForCapture(e);
                            OnFillErrorHandler(e, mapping.DataTable, mapping.DataValues);
                        }
                    }
                    else
                    {
                        await mapping.LoadDataRow();

                        rowsAddedToDataSet++;
                    }
                }
                // skip remaining rows of the first resultset
            }
            else
            {
                rowsAddedToDataSet = await FillLoadDataRowAsync(mapping);
            }
            return(rowsAddedToDataSet);
        }
Exemplo n.º 3
0
        internal async Task <object> FillSchemaFromReaderAsync(DataSet dataset, DataTable datatable, SchemaType schemaType, string srcTable, DbDataReader 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 (await dataReader.NextResultAsync()); // FillSchema does not capture errors for FillError event

            object value = dataTables;

            if ((null == value) && (null == datatable))
            { // WebData 101757
                value = new DataTable[0];
            }
            return(value); // null if datatable had no results
        }
Exemplo n.º 4
0
        private async Task <int> FillLoadDataRowAsync(SchemaMapping mapping)
        {
            int rowsAddedToDataSet         = 0;
            DataReaderContainer dataReader = mapping.DataReader;

            if (_hasFillErrorHandler)
            {
                while (await dataReader.ReadAsync())
                { // 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
                        await mapping.LoadDataRowWithClear();

                        rowsAddedToDataSet++;
                    }
                    catch (Exception e)
                    {
                        //
                        if (!ADP.IsCatchableExceptionType(e))
                        {
                            throw;
                        }
                        ADP.TraceExceptionForCapture(e);
                        OnFillErrorHandler(e, mapping.DataTable, mapping.DataValues);
                    }
                }
            }
            else
            {
                while (await dataReader.ReadAsync())
                { // read remaining rows of first and subsequent resultset
                    await mapping.LoadDataRow();

                    rowsAddedToDataSet++;
                }
            }
            return(rowsAddedToDataSet);
        }
Exemplo n.º 5
0
        virtual protected async Task <int> FillAsync(DataSet dataSet, string srcTable, IDataReader dataReader, int startRecord, int maxRecords)
        { // V1.2.3300, DbDataAdapter V1.0.3300
            IntPtr hscp;

            Bid.ScopeEnter(out hscp, "<comm.DataAdapter.Fill|API> %d#, dataSet, srcTable, dataReader, startRecord, maxRecords\n", ObjectID);
            try
            {
                if (null == dataSet)
                {
                    throw ADP.FillRequires("dataSet");
                }
                if (ADP.IsEmpty(srcTable))
                {
                    throw ADP.FillRequiresSourceTableName("srcTable");
                }
                if (null == dataReader)
                {
                    throw ADP.FillRequires("dataReader");
                }
                if (startRecord < 0)
                {
                    throw ADP.InvalidStartRecord("startRecord", startRecord);
                }
                if (maxRecords < 0)
                {
                    throw ADP.InvalidMaxRecords("maxRecords", maxRecords);
                }
                if (dataReader.IsClosed)
                {
                    return(0);
                }
                // user must Close/Dispose of the dataReader
                DataReaderContainer readerHandler = DataReaderContainer.Create(dataReader, ReturnProviderSpecificTypes);
                return(await FillFromReaderAsync(dataSet, null, srcTable, readerHandler, startRecord, maxRecords, null, null));
            }
            finally
            {
                Bid.ScopeLeave(ref hscp);
            }
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        private SchemaMapping FillMappingInternal(DataSet dataset, DataTable datatable, string srcTable, DataReaderContainer dataReader, int schemaCount, DataColumn parentChapterColumn, object parentChapterValue)
        {
            bool   withKeyInfo = (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));
        }
Exemplo n.º 8
0
        internal async Task <int> FillFromReaderAsync(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 = await FillLoadDataRowChunkAsync(mapping, startRecord, maxRecords);
                    }
                    else
                    {
                        int count = await FillLoadDataRowAsync(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 (await FillNextResultAsync(dataReader));

            return(rowsAddedToDataSet);
        }
Exemplo n.º 9
0
        virtual protected async Task <int> FillAsync(DataTable[] dataTables, IDataReader dataReader, int startRecord, int maxRecords)
        { // V1.2.3300
            IntPtr hscp;

            Bid.ScopeEnter(out hscp, "<comm.DataAdapter.Fill|API> %d#, dataTables[], dataReader, startRecord, maxRecords\n", ObjectID);
            try
            {
                ADP.CheckArgumentLength(dataTables, "tables");
                if ((null == dataTables) || (0 == dataTables.Length) || (null == dataTables[0]))
                {
                    throw ADP.FillRequires("dataTable");
                }
                if (null == dataReader)
                {
                    throw ADP.FillRequires("dataReader");
                }
                if ((1 < dataTables.Length) && ((0 != startRecord) || (0 != maxRecords)))
                {
                    throw ADP.NotSupported(); // FillChildren is not supported with FillPage
                }

                int     result            = 0;
                bool    enforceContraints = false;
                DataSet commonDataSet     = dataTables[0].DataSet;
                try
                {
                    if (null != commonDataSet)
                    {
                        enforceContraints = commonDataSet.EnforceConstraints;
                        commonDataSet.EnforceConstraints = false;
                    }
                    for (int i = 0; i < dataTables.Length; ++i)
                    {
                        Debug.Assert(null != dataTables[i], "null DataTable Fill");

                        if (dataReader.IsClosed)
                        {
#if DEBUG
                            Debug.Assert(!_debugHookNonEmptySelectCommand, "Debug hook asserts data reader should be open");
#endif
                            break;
                        }
                        DataReaderContainer readerHandler = DataReaderContainer.Create(dataReader, ReturnProviderSpecificTypes);
                        AssertReaderHandleFieldCount(readerHandler);
                        if (readerHandler.FieldCount <= 0)
                        {
                            if (i == 0)
                            {
                                bool lastFillNextResult;
                                do
                                {
                                    lastFillNextResult = await FillNextResultAsync(readerHandler);
                                }while (lastFillNextResult && readerHandler.FieldCount <= 0);
                                if (!lastFillNextResult)
                                {
                                    break;
                                }
                            }
                            else
                            {
                                continue;
                            }
                        }
                        if ((0 < i) && !await FillNextResultAsync(readerHandler))
                        {
                            break;
                        }
                        // user must Close/Dispose of the dataReader
                        // user will have to call NextResult to access remaining results
                        int count = await FillFromReaderAsync(null, dataTables[i], null, readerHandler, startRecord, maxRecords, null, null);

                        if (0 == i)
                        {
                            result = count;
                        }
                    }
                }
                catch (ConstraintException)
                {
                    enforceContraints = false;
                    throw;
                }
                finally
                {
                    if (enforceContraints)
                    {
                        commonDataSet.EnforceConstraints = true;
                    }
                }
                return(result);
            }
            finally
            {
                Bid.ScopeLeave(ref hscp);
            }
        }
Exemplo n.º 10
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
        }