mysql_connector/connection/bitflags.rs
1use {
2 crate::{
3 error::{InvalidFlags, ProtocolError},
4 Deserialize, Serialize,
5 },
6 std::convert::TryFrom,
7};
8
9macro_rules! bitflags {
10 (
11 $name:ident: $ty:ty {
12 $($body:tt)*
13 }
14 ) => {
15 paste::paste! {
16 impl TryFrom<$ty> for [< $name Flags >] {
17 type Error = InvalidFlags;
18
19 fn try_from(value: $ty) -> std::result::Result<[< $name Flags >], InvalidFlags> {
20 [< $name Flags >]::from_bits(value).ok_or_else(|| InvalidFlags::$name(value))
21 }
22 }
23
24 impl From<[< $name Flags >]> for $ty {
25 fn from(value: [< $name Flags >]) -> Self {
26 value.bits()
27 }
28 }
29
30 impl Default for [< $name Flags >] {
31 fn default() -> [< $name Flags >] {
32 [< $name Flags >]::empty()
33 }
34 }
35
36 impl Serialize for [< $name Flags >] {
37 fn serialize(&self, buf: &mut Vec<u8>) {
38 self.bits().serialize(buf)
39 }
40 }
41
42 impl<'de> Deserialize<'de> for [< $name Flags >] {
43 const SIZE: Option<usize> = <$ty as Deserialize<'de>>::SIZE;
44 type Ctx = <$ty as Deserialize<'de>>::Ctx;
45
46 fn deserialize(buf: &mut crate::ParseBuf<'de>, ctx: Self::Ctx) -> Result<Self, ProtocolError> {
47 let val = <$ty>::deserialize(buf, ctx)?;
48 Self::try_from(val).map_err(Into::into)
49 }
50 }
51
52 bitflags::bitflags! {
53 #[derive(PartialEq, Eq, Hash, Debug, Clone, Copy)]
54 pub struct [< $name Flags >]: $ty {
55 $($body)*
56 }
57 }
58 }
59 };
60}
61
62bitflags! {
63 Status: u16 {
64 /// Is raised when a multi-statement transaction has been started, either explicitly,
65 /// by means of BEGIN or COMMIT AND CHAIN, or implicitly, by the first transactional
66 /// statement, when autocommit=off.
67 const IN_TRANS = 0x0001;
68
69 /// Server in auto_commit mode.
70 const AUTOCOMMIT = 0x0002;
71
72 /// Multi query - next query exists.
73 const MORE_RESULTS_EXISTS = 0x0008;
74
75 const NO_GOOD_INDEX_USED = 0x0010;
76
77 const NO_INDEX_USED = 0x0020;
78
79 /// The server was able to fulfill the clients request and opened a read-only
80 /// non-scrollable cursor for a query. This flag comes in reply to COM_STMT_EXECUTE
81 /// and COM_STMT_FETCH commands. Used by Binary Protocol Resultset to signal that
82 /// COM_STMT_FETCH must be used to fetch the row-data.
83 const CURSOR_EXISTS = 0x0040;
84
85 /// This flag is sent when a read-only cursor is exhausted, in reply to
86 /// COM_STMT_FETCH command.
87 const LAST_ROW_SENT = 0x0080;
88
89 const DB_DROPPED = 0x0100;
90
91 const NO_BACKSLASH_ESCAPES = 0x0200;
92
93 /// Sent to the client if after a prepared statement reprepare we discovered
94 /// that the new statement returns a different number of result set columns.
95 const METADATA_CHANGED = 0x0400;
96
97 const QUERY_WAS_SLOW = 0x0800;
98
99 /// To mark ResultSet containing output parameter values.
100 const PS_OUT_PARAMS = 0x1000;
101
102 /// Set at the same time as SERVER_STATUS_IN_TRANS if the started multi-statement
103 /// transaction is a read-only transaction. Cleared when the transaction commits
104 /// or aborts. Since this flag is sent to clients in OK and EOF packets, the flag
105 /// indicates the transaction status at the end of command execution.
106 const IN_TRANS_READONLY = 0x2000;
107
108 /// This status flag, when on, implies that one of the state information has
109 /// changed on the server because of the execution of the last statement.
110 const SESSION_STATE_CHANGED = 0x4000;
111
112 /// Introduced by mariadb. Contain the information about ANSI_QUOTES SQL_MODE.
113 const ANSI_QUOTES = 0x8000;
114 }
115}
116
117bitflags! {
118 Capability: u32 {
119 /// Use the improved version of Old Password Authentication. Assumed to be set since 4.1.1.
120 const LONG_PASSWORD = 0x0000_0001;
121
122 /// Send found rows instead of affected rows in EOF_Packet.
123 const FOUND_ROWS = 0x0000_0002;
124
125 /// Get all column flags.
126 /// Longer flags in Protocol::ColumnDefinition320.
127 ///
128 /// ### Server
129 /// Supports longer flags.
130 ///
131 /// ### Client
132 /// Expects longer flags.
133 const LONG_FLAG = 0x0000_0004;
134
135 /// Database (schema) name can be specified on connect in Handshake Response Packet.
136 /// ### Server
137 /// Supports schema-name in Handshake Response Packet.
138 ///
139 /// ### Client
140 /// Handshake Response Packet contains a schema-name.
141 const CONNECT_WITH_DB = 0x0000_0008;
142
143 /// Don't allow database.table.column.
144 const NO_SCHEMA = 0x0000_0010;
145
146 /// Compression protocol supported.
147 ///
148 /// ### Server
149 /// Supports compression.
150 ///
151 /// ### Client
152 /// Switches to compressed protocol after successful authentication.
153 const COMPRESS = 0x0000_0020;
154
155 /// Special handling of ODBC behavior.
156 const ODBC = 0x0000_0040;
157
158 /// Can use LOAD DATA LOCAL.
159 ///
160 /// ### Server
161 /// Enables the LOCAL INFILE request of LOAD DATA|XML.
162 ///
163 /// ### Client
164 /// Will handle LOCAL INFILE request.
165 const LOCAL_FILES = 0x0000_0080;
166
167 /// Ignore spaces before '('.
168 const IGNORE_SPACE = 0x0000_0100;
169
170 const PROTOCOL_41 = 0x0000_0200;
171
172 /// This is an interactive client.
173 const INTERACTIVE = 0x0000_0400;
174
175 /// Use SSL encryption for the session.
176 ///
177 /// ### Server
178 /// Supports SSL
179 ///
180 /// ### Client
181 /// Switch to SSL after sending the capability-flags.
182 const SSL = 0x0000_0800;
183
184 /// Client only flag. Not used.
185 ///
186 /// ### Client
187 /// Do not issue SIGPIPE if network failures occur (libmysqlclient only).
188 const IGNORE_SIGPIPE = 0x0000_1000;
189
190 /// Client knows about transactions.
191 ///
192 /// ### Server
193 /// Can send status flags in OK_Packet / EOF_Packet.
194 ///
195 /// ### Client
196 /// Expects status flags in OK_Packet / EOF_Packet.
197 ///
198 /// ### Note
199 /// This flag is optional in 3.23, but always set by the server since 4.0.
200 const TRANSACTIONS = 0x0000_2000;
201
202 const RESERVED = 0x0000_4000;
203
204 const SECURE_CONNECTION = 0x0000_8000;
205
206 /// Enable/disable multi-stmt support.
207 /// Also sets MULTI_RESULTS.
208 const MULTI_STATEMENTS = 0x0001_0000;
209
210 /// Enable/disable multi-results.
211 ///
212 /// ### Server
213 /// Can send multiple resultsets for COM_QUERY. Error if the server needs to send
214 /// them and client does not support them.
215 ///
216 /// ### Client
217 /// Can handle multiple resultsets for COM_QUERY.
218 ///
219 /// ### Requires
220 /// `PROTOCOL_41`
221 const MULTI_RESULTS = 0x0002_0000;
222
223 /// Multi-results and OUT parameters in PS-protocol.
224 ///
225 /// ### Requires
226 /// `PROTOCOL_41`
227 const PS_MULTI_RESULTS = 0x0004_0000;
228
229 /// Client supports plugin authentication.
230 ///
231 /// ### Server
232 /// Sends extra data in Initial Handshake Packet and supports the pluggable
233 /// authentication protocol.
234 ///
235 /// ### Client
236 /// Supports authentication plugins.
237 ///
238 /// ### Requires
239 /// `PROTOCOL_41`
240 const PLUGIN_AUTH = 0x0008_0000;
241
242 /// Client supports connection attributes in handshake response.
243 const CONNECT_ATTRS = 0x0010_0000;
244
245 /// Enable authentication response packet to be larger than 255 bytes.
246 /// When the ability to change default plugin require that the initial password
247 /// field in the Protocol::HandshakeResponse41 paclet can be of arbitrary size.
248 /// However, the 4.1 client-server protocol limits the length of the auth-data-field
249 /// sent from client to server to 255 bytes. The solution is to change the type of
250 /// the field to a true length encoded string and indicate the protocol change with
251 /// this client capability flag.
252 ///
253 /// ### Server
254 /// Understands length-encoded integer for auth response data in
255 /// Protocol::HandshakeResponse41.
256 ///
257 /// ### Client
258 /// Length of auth response data in Protocol::HandshakeResponse41 is a
259 /// length-encoded integer.
260 ///
261 /// ### Note
262 /// The flag was introduced in 5.6.6, but had the wrong value.
263 const PLUGIN_AUTH_LENENC_CLIENT_DATA = 0x0020_0000;
264
265 /// Don't close the connection for a user account with expired password.
266 const CAN_HANDLE_EXPIRED_PASSWORDS = 0x0040_0000;
267
268 /// Capable of handling server state change information.
269 /// Its a hint to the server to include the state change information in OK_Packet.
270 ///
271 /// ### Server
272 /// Can set SESSION_STATE_CHANGED in the StatusFlags and send
273 /// Session State Information in a OK_Packet.
274 ///
275 /// ### Client
276 /// Expects the server to send Session State Information in a OK_Packet.
277 const SESSION_TRACK = 0x0080_0000;
278
279 /// Client no longer needs EOF_Packet and will use OK_Packet instead.
280 ///
281 /// ### Server
282 /// Can send OK after a Text Resultset.
283 ///
284 /// ### Client
285 /// Expects an OK_Packet (instead of EOF_Packet) after the resultset
286 /// rows of a Text Resultset.
287 ///
288 /// ### Background
289 /// To support SESSION_TRACK, additional information must be sent after all
290 /// successful commands. Although the OK_Packet is extensible, the EOF_Packet is
291 /// not due to the overlap of its bytes with the content of the Text Resultset Row.
292 ///
293 /// Therefore, the EOF_Packet in the Text Resultset is replaced with an OK_Packet.
294 /// EOF_Packet is deprecated as of MySQL 5.7.5.
295 const DEPRECATE_EOF = 0x0100_0000;
296
297 /// The client can handle optional metadata information in the resultset.
298 const OPTIONAL_RESULTSET_METADATA = 0x0200_0000;
299
300 /// Compression protocol extended to support zstd compression method.
301 ///
302 /// This capability flag is used to send zstd compression level between client and server
303 /// provided both client and server are enabled with this flag.
304 ///
305 /// # Server
306 ///
307 /// Server sets this flag when global variable protocol-compression-algorithms has zstd
308 /// in its list of supported values.
309 ///
310 /// # Client
311 ///
312 /// Client sets this flag when it is configured to use zstd compression method.
313 const ZSTD_COMPRESSION_ALGORITHM = 0x0400_0000;
314
315 /// Support optional extension for query parameters into the COM_QUERY
316 /// and COM_STMT_EXECUTE packets.
317 ///
318 /// # Server
319 ///
320 /// Expects an optional part containing the query parameter set(s).
321 /// Executes the query for each set of parameters or returns an error if more than 1 set
322 /// of parameters is sent and the server can't execute it.
323 ///
324 /// # Client
325 ///
326 /// Can send the optional part containing the query parameter set(s).
327 const QUERY_ATTRIBUTES = 0x0800_0000;
328
329 /// Support Multi factor authentication.
330 ///
331 /// # Server
332 ///
333 /// Server sends AuthNextFactor packet after every nth factor
334 /// authentication method succeeds, except the last factor authentication.
335 ///
336 /// # Client
337 ///
338 /// Client reads AuthNextFactor packet sent by server
339 /// and initiates next factor authentication method.
340 const MULTI_FACTOR_AUTHENTICATION = 0x1000_0000;
341
342 /// Client or server supports progress reports within error packet.
343 const PROGRESS_OBSOLETE = 0x2000_0000;
344
345 /// Verify server certificate. Client only flag.
346 ///
347 /// Deprecated in favor of –ssl-mode.
348 const SSL_VERIFY_SERVER_CERT = 0x4000_0000;
349
350 /// Don't reset the options after an unsuccessful connect. Client only flag.
351 const REMEMBER_OPTIONS = 0x8000_0000;
352 }
353}
354
355bitflags! {
356 CursorType: u8 {
357 const NO_CURSOR = 0_u8;
358 const READ_ONLY = 1_u8;
359 const FOR_UPDATE = 2_u8;
360 const SCROLLABLE = 4_u8;
361 }
362}
363
364bitflags! {
365 StmtExecuteParams: u8 {
366 const NEW_PARAMS_BOUND = 1_u8;
367 }
368}
369
370bitflags! {
371 StmtExecuteParam: u8 {
372 const UNSIGNED = 128_u8;
373 }
374}
375
376bitflags! {
377 Column: u16 {
378 /// Field can't be NULL.
379 const NOT_NULL_FLAG = 1u16;
380
381 /// Field is part of a primary key.
382 const PRI_KEY_FLAG = 2u16;
383
384 /// Field is part of a unique key.
385 const UNIQUE_KEY_FLAG = 4u16;
386
387 /// Field is part of a key.
388 const MULTIPLE_KEY_FLAG = 8u16;
389
390 /// Field is a blob.
391 const BLOB_FLAG = 16u16;
392
393 /// Field is unsigned.
394 const UNSIGNED_FLAG = 32u16;
395
396 /// Field is zerofill.
397 const ZEROFILL_FLAG = 64u16;
398
399 /// Field is binary.
400 const BINARY_FLAG = 128u16;
401
402 /// Field is an enum.
403 const ENUM_FLAG = 256u16;
404
405 /// Field is a autoincrement field.
406 const AUTO_INCREMENT_FLAG = 512u16;
407
408 /// Field is a timestamp.
409 const TIMESTAMP_FLAG = 1024u16;
410
411 /// Field is a set.
412 const SET_FLAG = 2048u16;
413
414 /// Field doesn't have default value.
415 const NO_DEFAULT_VALUE_FLAG = 4096u16;
416
417 /// Field is set to NOW on UPDATE.
418 const ON_UPDATE_NOW_FLAG = 8192u16;
419
420 /// Intern; Part of some key.
421 const PART_KEY_FLAG = 16384u16;
422
423 /// Field is num (for clients).
424 const NUM_FLAG = 32768u16;
425 }
426}