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