Esempio n. 1
0
        public async Task Handle(DbDataReader reader, CancellationToken token)
        {
            var hasNext = await reader.NextResultAsync(token).ConfigureAwait(false);

            if (!hasNext)
            {
                throw new InvalidOperationException("There is no next result to read over.");
            }

            await _inner.Handle(reader, token).ConfigureAwait(false);
        }
Esempio n. 2
0
 /// <summary>
 ///     Asynchronously consumes all rows and result sets from the reader. This allows client to retrieve
 ///     parameter values and intercept any store exceptions.
 /// </summary>
 internal static async Task ConsumeReaderAsync(DbDataReader reader, CancellationToken cancellationToken)
 {
     if (null != reader
         && !reader.IsClosed)
     {
         while (await reader.NextResultAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext: false))
         {
             // Note that we only walk through the result sets. We don't need
             // to walk through individual rows (though underlying provider
             // implementation may do so)
         }
     }
 }
Esempio n. 3
0
        // <summary>
        // Asynchronously consumes all rows and result sets from the reader. This allows client to retrieve
        // parameter values and intercept any store exceptions.
        // </summary>
        internal static async Task ConsumeReaderAsync(DbDataReader reader, CancellationToken cancellationToken)
        {
            if (null != reader
                && !reader.IsClosed)
            {
                cancellationToken.ThrowIfCancellationRequested();

                while (await reader.NextResultAsync(cancellationToken).WithCurrentCulture())
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    // Note that we only walk through the result sets. We don't need
                    // to walk through individual rows (though underlying provider
                    // implementation may do so)
                }
            }
        }
        protected override async Task ConsumeAsync(
            DbDataReader reader,
            DbContext context,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            Debug.Assert(ResultSetEnds.Count == ModificationCommands.Count);
            var commandIndex = 0;

            try
            {
                var actualResultSetCount = 0;
                do
                {
                    commandIndex = ModificationCommands[commandIndex].RequiresResultPropagation
                        ? await ConsumeResultSetWithPropagationAsync(commandIndex, reader, context, cancellationToken)
                        : await ConsumeResultSetWithoutPropagationAsync(commandIndex, reader, context, cancellationToken);
                    actualResultSetCount++;
                }
                while (commandIndex < ResultSetEnds.Count
                       && await reader.NextResultAsync(cancellationToken));

                Debug.Assert(commandIndex == ModificationCommands.Count, "Expected " + ModificationCommands.Count + " results, got " + commandIndex);
#if DEBUG
                var expectedResultSetCount = 1 + ResultSetEnds.Count(e => e);
                expectedResultSetCount += ResultSetEnds[ResultSetEnds.Count - 1] ? -1 : 0;

                Debug.Assert(actualResultSetCount == expectedResultSetCount, "Expected " + expectedResultSetCount + " result sets, got " + actualResultSetCount);
#endif
            }
            catch (DbUpdateException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new DbUpdateException(
                    Strings.UpdateStoreException,
                    ex,
                    ModificationCommands[commandIndex].Entries);
            }
        }
        protected override async Task ConsumeAsync(
            DbDataReader reader,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            Debug.Assert(CommandResultSet.Count == ModificationCommands.Count);
            var commandIndex = 0;

            try
            {
                var actualResultSetCount = 0;
                do
                {
                    while (commandIndex < CommandResultSet.Count
                           && CommandResultSet[commandIndex] == ResultSetMapping.NoResultSet)
                    {
                        commandIndex++;
                    }

                    if (commandIndex < CommandResultSet.Count)
                    {
                        commandIndex = ModificationCommands[commandIndex].RequiresResultPropagation
                            ? await ConsumeResultSetWithPropagationAsync(commandIndex, reader, cancellationToken)
                            : await ConsumeResultSetWithoutPropagationAsync(commandIndex, reader, cancellationToken);
                        actualResultSetCount++;
                    }
                }
                while (commandIndex < CommandResultSet.Count
                       && await reader.NextResultAsync(cancellationToken));

#if DEBUG
                while (commandIndex < CommandResultSet.Count
                       && CommandResultSet[commandIndex] == ResultSetMapping.NoResultSet)
                {
                    commandIndex++;
                }

                Debug.Assert(commandIndex == ModificationCommands.Count,
                    "Expected " + ModificationCommands.Count + " results, got " + commandIndex);

                var expectedResultSetCount = CommandResultSet.Count(e => e == ResultSetMapping.LastInResultSet);

                Debug.Assert(actualResultSetCount == expectedResultSetCount,
                    "Expected " + expectedResultSetCount + " result sets, got " + actualResultSetCount);
#endif
            }
            catch (DbUpdateException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new DbUpdateException(
                    RelationalStrings.UpdateStoreException,
                    ex,
                    ModificationCommands[commandIndex].Entries);
            }
        }
Esempio n. 6
0
        private async Task<long> getLong(DbDataReader reader)
        {
            await reader.NextResultAsync(_token).ConfigureAwait(false);
            bool isAny = await reader.ReadAsync(_token).ConfigureAwait(false);

            if (!isAny) return 0;

            if (await reader.IsDBNullAsync(0, _token).ConfigureAwait(false))
            {
                return 0;
            }

            return await reader.GetFieldValueAsync<long>(0, _token).ConfigureAwait(false);
        }