Repository navigation
Expand file tree
/
Copy pathOracle.DataReader.cs
More file actions
68 lines (66 loc) · 2.96 KB
/
Copy pathOracle.DataReader.cs
File metadata and controls
68 lines (66 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System.Data;
using System.Data.Common;
using Oracle.ManagedDataAccess.Client;
namespace DBAClientX;
public partial class Oracle
{
/// <summary>Opens an Oracle query as an owned, forward-only streaming reader.</summary>
/// <remarks>
/// Dispose the returned reader after the consumer, including OfficeIMO.Data.Arrow, has finished reading.
/// </remarks>
public virtual async Task<DbaDataReader> QueryReaderAsync(
string connectionString,
string query,
IDictionary<string, object?>? parameters = null,
bool useTransaction = false,
CancellationToken cancellationToken = default,
IDictionary<string, OracleDbType>? parameterTypes = null,
IDictionary<string, ParameterDirection>? parameterDirections = null)
{
ValidateConnectionString(connectionString);
ValidateCommandText(query);
OracleConnection? connection = null;
OracleCommand? command = null;
var dispose = false;
try
{
var resolved = await ResolveConnectionAsync(connectionString, useTransaction, cancellationToken).ConfigureAwait(false);
(connection, var transaction, dispose) = resolved;
command = connection.CreateCommand();
command.CommandText = query;
command.Transaction = transaction;
command.BindByName = true;
AddParameters(command, parameters, ConvertParameterTypes(parameterTypes), parameterDirections);
ApplyCommandTimeout(command);
var reader = await ExecuteReaderWithDiagnosticsAsync(
() => AwaitWithCallerCancellationAsync(
() => command.ExecuteReaderAsync(CommandBehavior.SequentialAccess, cancellationToken),
cancellationToken),
connection,
transaction,
query,
cancellationToken).ConfigureAwait(false);
return new DbaDataReader(
reader,
command,
connection,
dispose,
resource => DisposeConnection((OracleConnection)resource),
() => UpdateOutputParameters(command, parameters),
resource => DisposeConnectionAsync((OracleConnection)resource),
afterReaderDisposedAsync: null,
consumptionExceptionFactory: (exception, token) => CreateQueryExecutionOrCancellationException(
"Failed while consuming query reader.", query, exception, token));
}
catch (Exception ex)
{
command?.Dispose();
if (connection != null && dispose)
{
await DisposeOwnedResourceAsync(connection, true, DisposeConnectionAsync).ConfigureAwait(false);
}
if (IsCallerCancellation(ex, cancellationToken)) throw;
throw CreateQueryExecutionOrCancellationException("Failed to open query reader.", query, ex, cancellationToken);
}
}
}