1 module hunt.database.driver.mysql.impl.codec.Packets;
2 
3 /**
4  * MySQL Packets.
5  */
6 enum Packets : int {
7     OK_PACKET_HEADER = 0x00,
8     EOF_PACKET_HEADER = 0xFE,
9     ERROR_PACKET_HEADER = 0xFF,
10     PACKET_PAYLOAD_LENGTH_LIMIT = 0xFFFFFF
11 }
12 
13 
14 /**
15  * 
16  */
17 static final class OkPacket {
18 
19     private long _affectedRows;
20     private long _lastInsertId;
21     private int _serverStatusFlags;
22     private int _numberOfWarnings;
23     private string _statusInfo;
24     private string _sessionStateInfo;
25 
26     this(long affectedRows, long lastInsertId, int serverStatusFlags, int numberOfWarnings, 
27             string statusInfo, string sessionStateInfo) {
28         this._affectedRows = affectedRows;
29         this._lastInsertId = lastInsertId;
30         this._serverStatusFlags = serverStatusFlags;
31         this._numberOfWarnings = numberOfWarnings;
32         this._statusInfo = statusInfo;
33         this._sessionStateInfo = sessionStateInfo;
34     }
35 
36     long affectedRows() {
37         return _affectedRows;
38     }
39 
40     long lastInsertId() {
41         return _lastInsertId;
42     }
43 
44     int serverStatusFlags() {
45         return _serverStatusFlags;
46     }
47 
48     int numberOfWarnings() {
49         return _numberOfWarnings;
50     }
51 
52     string statusInfo() {
53         return _statusInfo;
54     }
55 
56     string sessionStateInfo() {
57         return _sessionStateInfo;
58     }
59 }
60 
61 
62 /**
63  * 
64  */
65 final class EofPacket {
66 
67     private int _numberOfWarnings;
68     private int _serverStatusFlags;
69 
70     this(int numberOfWarnings, int serverStatusFlags) {
71         this._numberOfWarnings = numberOfWarnings;
72         this._serverStatusFlags = serverStatusFlags;
73     }
74 
75     int numberOfWarnings() {
76         return _numberOfWarnings;
77     }
78 
79     int serverStatusFlags() {
80         return _serverStatusFlags;
81     }
82 }
83 
84 enum ServerStatusFlags : int {
85     /*
86         https://dev.mysql.com/doc/dev/mysql-server/latest/mysql__com_8h.html#a1d854e841086925be1883e4d7b4e8cad
87      */
88 
89     SERVER_STATUS_IN_TRANS = 0x0001,
90     SERVER_STATUS_AUTOCOMMIT = 0x0002,
91     SERVER_MORE_RESULTS_EXISTS = 0x0008,
92     SERVER_STATUS_NO_GOOD_INDEX_USED = 0x0010,
93     SERVER_STATUS_NO_INDEX_USED = 0x0020,
94     SERVER_STATUS_CURSOR_EXISTS = 0x0040,
95     SERVER_STATUS_LAST_ROW_SENT = 0x0080,
96     SERVER_STATUS_DB_DROPPED = 0x0100,
97     SERVER_STATUS_NO_BACKSLASH_ESCAPES = 0x0200,
98     SERVER_STATUS_METADATA_CHANGED = 0x0400,
99     SERVER_QUERY_WAS_SLOW = 0x0800,
100     SERVER_PS_OUT_PARAMS = 0x1000,
101     SERVER_STATUS_IN_TRANS_READONLY = 0x2000,
102     SERVER_SESSION_STATE_CHANGED = 0x4000
103 }