forked from danbarua/Npgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryManager.cs
More file actions
executable file
·74 lines (68 loc) · 3.01 KB
/
QueryManager.cs
File metadata and controls
executable file
·74 lines (68 loc) · 3.01 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
72
73
74
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
namespace Npgsql
{
/// <summary>
/// Responsible for creating query messages and writing them to the wire.
///
/// Contains some frequently-used queries as buffers ready to be sent.
/// </summary>
internal static class QueryManager
{
internal static void WriteQuery(Stream stream, string query)
{
WriteQuery(stream, BackendEncoding.UTF8Encoding.GetBytes(query));
}
#if NET45
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
internal static void WriteQuery(Stream stream, byte[] query)
{
var len = 4 + query.Length + 1;
stream
.WriteByte(ASCIIByteArrays.QueryMessageCode)
.WriteInt32(len)
.WriteBytesNullTerminated(query)
.Flush();
}
static QueryManager()
{
BeginTransRepeatableRead = BuildQuery("BEGIN; SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;");
BeginTransSerializable = BuildQuery("BEGIN; SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;");
BeginTransReadCommitted = BuildQuery("BEGIN; SET TRANSACTION ISOLATION LEVEL READ COMMITTED;");
CommitTransaction = BuildQuery("COMMIT");
RollbackTransaction = BuildQuery("ROLLBACK");
DiscardAll = BuildQuery("DISCARD ALL");
UnlistenAll = BuildQuery("UNLISTEN *");
SetStmtTimeout10Sec = BuildQuery("SET statement_timeout = 10000");
SetStmtTimeout20Sec = BuildQuery("SET statement_timeout = 20000");
SetStmtTimeout30Sec = BuildQuery("SET statement_timeout = 30000");
SetStmtTimeout60Sec = BuildQuery("SET statement_timeout = 60000");
SetStmtTimeout90Sec = BuildQuery("SET statement_timeout = 90000");
SetStmtTimeout120Sec = BuildQuery("SET statement_timeout = 120000");
}
static byte[] BuildQuery(string query)
{
var ms = new MemoryStream();
WriteQuery(ms, query);
return ms.ToArray();
}
internal static readonly byte[] BeginTransRepeatableRead;
internal static readonly byte[] BeginTransSerializable;
internal static readonly byte[] BeginTransReadCommitted;
internal static readonly byte[] CommitTransaction;
internal static readonly byte[] RollbackTransaction;
internal static readonly byte[] DiscardAll;
internal static readonly byte[] UnlistenAll;
internal static readonly byte[] SetStmtTimeout10Sec;
internal static readonly byte[] SetStmtTimeout20Sec;
internal static readonly byte[] SetStmtTimeout30Sec;
internal static readonly byte[] SetStmtTimeout60Sec;
internal static readonly byte[] SetStmtTimeout90Sec;
internal static readonly byte[] SetStmtTimeout120Sec;
}
}