rbdc_mysql/protocol/statement/execute.rs
1use crate::protocol::Capabilities;
2use crate::stmt::MySqlArguments;
3use rbdc::io::Encode;
4
5// https://dev.mysql.com/doc/internals/en/com-stmt-execute.html
6
7/// Execute
8/// payload:
9/// 1 [17] COM_STMT_EXECUTE
10/// 4 stmt-id
11/// 1 flags
12/// 4 iteration-count
13/// if num-params > 0:
14/// n NULL-bitmap, length: (num-params+7)/8
15/// 1 new-params-bound-flag
16/// if new-params-bound-flag == 1:
17/// n type of each parameter, length: num-params * 2
18/// n value of each parameter
19///
20/// example:
21/// 12 00 00 00 17 01 00 00 00 00 01 00 00 00 00 01 ................
22/// 0f 00 03 66 6f 6f ...foo
23#[derive(Debug)]
24pub struct Execute<'q> {
25 pub statement_id: u32,
26 pub arguments: &'q MySqlArguments,
27}
28
29impl<'q> Encode<'_, Capabilities> for Execute<'q> {
30 fn encode_with(&self, buf: &mut Vec<u8>, _: Capabilities) {
31 buf.push(0x17); // COM_STMT_EXECUTE
32 buf.extend(&self.statement_id.to_le_bytes());
33 buf.push(0); // NO_CURSOR
34 buf.extend(&1_u32.to_le_bytes()); // iterations (always 1): int<4>
35
36 if !self.arguments.types.is_empty() {
37 buf.extend(&*self.arguments.null_bitmap);
38 buf.push(1); // send type to server
39
40 for ty in &self.arguments.types {
41 buf.push(ty.r#type as u8);
42 buf.push(0);
43 }
44
45 buf.extend(&*self.arguments.values);
46 }
47 }
48}