forked from npgsql/npgsql
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathNpgsqlDataSourceCommand.cs
More file actions
71 lines (61 loc) · 2.29 KB
/
NpgsqlDataSourceCommand.cs
File metadata and controls
71 lines (61 loc) · 2.29 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
69
70
71
using System;
using System.Data;
using System.Data.Common;
using System.Threading;
using System.Threading.Tasks;
using Npgsql.Properties;
namespace Npgsql;
sealed class NpgsqlDataSourceCommand : NpgsqlCommand
{
internal NpgsqlDataSourceCommand(NpgsqlConnection connection)
: base(cmdText: null, connection)
{
}
// For NpgsqlBatch only
internal NpgsqlDataSourceCommand(NpgsqlBatch batch, int batchCommandCapacity, NpgsqlConnection connection)
: base(batch, batchCommandCapacity, connection)
{
}
internal override async ValueTask<NpgsqlDataReader> ExecuteReader(
bool async, CommandBehavior behavior,
CancellationToken cancellationToken)
{
await InternalConnection!.Open(async, cancellationToken).ConfigureAwait(false);
try
{
return await base.ExecuteReader(
async,
behavior | CommandBehavior.CloseConnection,
cancellationToken)
.ConfigureAwait(false);
}
catch
{
try
{
await InternalConnection.Close(async).ConfigureAwait(false);
}
catch
{
// Swallow to allow the original exception to bubble up
}
throw;
}
}
// The below are incompatible with commands executed directly against DbDataSource, since no DbConnection
// is involved at the user API level and the command owns the DbConnection.
public override void Prepare()
=> throw new NotSupportedException(NpgsqlStrings.NotSupportedOnDataSourceCommand);
public override Task PrepareAsync(CancellationToken cancellationToken = default)
=> throw new NotSupportedException(NpgsqlStrings.NotSupportedOnDataSourceCommand);
protected override DbConnection? DbConnection
{
get => throw new NotSupportedException(NpgsqlStrings.NotSupportedOnDataSourceCommand);
set => throw new NotSupportedException(NpgsqlStrings.NotSupportedOnDataSourceCommand);
}
protected override DbTransaction? DbTransaction
{
get => throw new NotSupportedException(NpgsqlStrings.NotSupportedOnDataSourceCommand);
set => throw new NotSupportedException(NpgsqlStrings.NotSupportedOnDataSourceCommand);
}
}