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