sqlx_core_oldapi/odbc/
arguments.rs

1use crate::arguments::Arguments;
2use crate::encode::Encode;
3use crate::odbc::Odbc;
4use crate::types::Type;
5
6#[derive(Default, Debug)]
7pub struct OdbcArguments {
8    pub(crate) values: Vec<OdbcArgumentValue>,
9}
10
11#[derive(Debug, Clone)]
12pub enum OdbcArgumentValue {
13    Text(String),
14    Bytes(Vec<u8>),
15    Int(i64),
16    Float(f64),
17    Null,
18}
19
20impl<'q> Arguments<'q> for OdbcArguments {
21    type Database = Odbc;
22
23    fn reserve(&mut self, additional: usize, _size: usize) {
24        self.values.reserve(additional);
25    }
26
27    fn add<T>(&mut self, value: T)
28    where
29        T: 'q + Send + Encode<'q, Self::Database> + Type<Self::Database>,
30    {
31        let _ = value.encode(&mut self.values);
32    }
33}
34
35// Encode implementations are now in the types module
36
37impl<'q, T> Encode<'q, Odbc> for Option<T>
38where
39    T: Encode<'q, Odbc> + Type<Odbc> + 'q,
40{
41    fn produces(&self) -> Option<crate::odbc::OdbcTypeInfo> {
42        if let Some(v) = self {
43            v.produces()
44        } else {
45            T::type_info().into()
46        }
47    }
48
49    fn encode(self, buf: &mut Vec<OdbcArgumentValue>) -> crate::encode::IsNull {
50        match self {
51            Some(v) => v.encode(buf),
52            None => {
53                buf.push(OdbcArgumentValue::Null);
54                crate::encode::IsNull::Yes
55            }
56        }
57    }
58
59    fn encode_by_ref(&self, buf: &mut Vec<OdbcArgumentValue>) -> crate::encode::IsNull {
60        match self {
61            Some(v) => v.encode_by_ref(buf),
62            None => {
63                buf.push(OdbcArgumentValue::Null);
64                crate::encode::IsNull::Yes
65            }
66        }
67    }
68
69    fn size_hint(&self) -> usize {
70        self.as_ref().map_or(0, Encode::size_hint)
71    }
72}