/
germanubis
/
sqlx
ΠΠ±Π·ΠΎΡ
ΠΠΎΠΊΡΠΌΠ΅Π½ΡΠ°ΡΠΈΡ
ΠΠΎΠΉΡΠΈ
/
germanubis
/
sqlx
ΠΠΎΠ΄
ΠΠ°ΠΏΡΠΎΡΡ
0
ΠΠ°Π΄Π°ΡΠΈ
ΠΠΈΠΊΠΈ
ΠΠ°ΠΊΠ΅ΡΡ
0
Π Π΅Π»ΠΈΠ·Ρ
0
ΠΠ½Π°Π»ΠΈΡΠΈΠΊΠ°
ΠΠ΅Π·ΠΎΠΏΠ°ΡΠ½ΠΎΡΡΡ
v0.7.2
sqlx-postgres/src/message/parse.rs
56 ΡΡΡΠΎΠΊ
1 KB
Austin Bonander
Break drivers out into separate crates, clean up some technical debt (#2039)
22 ΡΠ΅Π² 2023, 00:25
22 ΡΠ΅Π² 2023, 00:25
b5312c3
ΠΠΎΠ΄
ΠΠ²ΡΠΎΡΡΡΠ²ΠΎ
Π ΡΡΠΌ ΠΊΠΎΠ΄?
use std::i16; use crate::io::PgBufMutExt; use crate::io::{BufMutExt, Encode}; use crate::types::Oid; #[derive(Debug)] pub struct Parse<'a> { /// The ID of the destination prepared statement. pub statement: Oid, /// The query string to be parsed. pub query: &'a str, /// The parameter data types specified (could be zero). Note that this is not an /// indication of the number of parameters that might appear in the query string, /// only the number that the frontend wants to pre-specify types for. pub param_types: &'a [Oid], } impl Encode<'_> for Parse<'_> { fn encode_with(&self, buf: &mut Vec<u8>, _: ()) { buf.push(b'P'); buf.put_length_prefixed(|buf| { buf.put_statement_name(self.statement); buf.put_str_nul(self.query); // TODO: Return an error here instead assert!(self.param_types.len() <= (u16::MAX as usize)); buf.extend(&(self.param_types.len() as i16).to_be_bytes()); for &oid in self.param_types { buf.extend(&oid.0.to_be_bytes()); } }) } } #[test] fn test_encode_parse() { const EXPECTED: &[u8] = b"P\0\0\0\x1dsqlx_s_1\0SELECT $1\0\0\x01\0\0\0\x19"; let mut buf = Vec::new(); let m = Parse { statement: Oid(1), query: "SELECT $1", param_types: &[Oid(25)], }; m.encode(&mut buf); assert_eq!(buf, EXPECTED); }