sqlx_core_oldapi/postgres/message/
execute.rs

1use crate::io::Encode;
2use crate::postgres::io::PgBufMutExt;
3use crate::postgres::types::Oid;
4
5pub struct Execute {
6    /// The id of the portal to execute (`None` selects the unnamed portal).
7    pub portal: Option<Oid>,
8
9    /// Maximum number of rows to return, if portal contains a query
10    /// that returns rows (ignored otherwise). Zero denotes “no limit”.
11    pub limit: u32,
12}
13
14impl Encode<'_> for Execute {
15    fn encode_with(&self, buf: &mut Vec<u8>, _: ()) {
16        buf.reserve(20);
17        buf.push(b'E');
18
19        buf.put_length_prefixed(|buf| {
20            buf.put_portal_name(self.portal);
21            buf.extend(&self.limit.to_be_bytes());
22        });
23    }
24}
25
26#[test]
27fn test_encode_execute() {
28    const EXPECTED: &[u8] = b"E\0\0\0\x11sqlx_p_5\0\0\0\0\x02";
29
30    let mut buf = Vec::new();
31    let m = Execute {
32        portal: Some(Oid(5)),
33        limit: 2,
34    };
35
36    m.encode(&mut buf);
37
38    assert_eq!(buf, EXPECTED);
39}