forked from launchbadge/sqlx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
execute.rs
39 lines (31 loc) · 949 Bytes
/
execute.rs
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
use crate::io::Encode;
use crate::postgres::io::PgBufMutExt;
use crate::postgres::types::Oid;
pub struct Execute {
/// The id of the portal to execute (`None` selects the unnamed portal).
pub portal: Option<Oid>,
/// Maximum number of rows to return, if portal contains a query
/// that returns rows (ignored otherwise). Zero denotes “no limit”.
pub limit: u32,
}
impl Encode<'_> for Execute {
fn encode_with(&self, buf: &mut Vec<u8>, _: ()) {
buf.reserve(20);
buf.push(b'E');
buf.put_length_prefixed(|buf| {
buf.put_portal_name(self.portal);
buf.extend(&self.limit.to_be_bytes());
});
}
}
#[test]
fn test_encode_execute() {
const EXPECTED: &[u8] = b"E\0\0\0\x11sqlx_p_5\0\0\0\0\x02";
let mut buf = Vec::new();
let m = Execute {
portal: Some(Oid(5)),
limit: 2,
};
m.encode(&mut buf);
assert_eq!(buf, EXPECTED);
}