sqlx_core_oldapi/odbc/
value.rs

1use crate::odbc::{Odbc, OdbcTypeInfo};
2use crate::value::{Value, ValueRef};
3use std::borrow::Cow;
4
5#[derive(Debug)]
6pub struct OdbcValueRef<'r> {
7    pub(crate) type_info: OdbcTypeInfo,
8    pub(crate) is_null: bool,
9    pub(crate) text: Option<&'r str>,
10    pub(crate) blob: Option<&'r [u8]>,
11    pub(crate) int: Option<i64>,
12    pub(crate) float: Option<f64>,
13}
14
15#[derive(Debug, Clone)]
16pub struct OdbcValue {
17    pub(crate) type_info: OdbcTypeInfo,
18    pub(crate) is_null: bool,
19    pub(crate) text: Option<String>,
20    pub(crate) blob: Option<Vec<u8>>,
21    pub(crate) int: Option<i64>,
22    pub(crate) float: Option<f64>,
23}
24
25impl<'r> ValueRef<'r> for OdbcValueRef<'r> {
26    type Database = Odbc;
27
28    fn to_owned(&self) -> OdbcValue {
29        OdbcValue {
30            type_info: self.type_info.clone(),
31            is_null: self.is_null,
32            text: self.text.map(|s| s.to_string()),
33            blob: self.blob.map(|b| b.to_vec()),
34            int: self.int,
35            float: self.float,
36        }
37    }
38
39    fn type_info(&self) -> Cow<'_, OdbcTypeInfo> {
40        Cow::Borrowed(&self.type_info)
41    }
42    fn is_null(&self) -> bool {
43        self.is_null
44    }
45}
46
47impl Value for OdbcValue {
48    type Database = Odbc;
49
50    fn as_ref(&self) -> OdbcValueRef<'_> {
51        OdbcValueRef {
52            type_info: self.type_info.clone(),
53            is_null: self.is_null,
54            text: self.text.as_deref(),
55            blob: self.blob.as_deref(),
56            int: self.int,
57            float: self.float,
58        }
59    }
60
61    fn type_info(&self) -> Cow<'_, OdbcTypeInfo> {
62        Cow::Borrowed(&self.type_info)
63    }
64    fn is_null(&self) -> bool {
65        self.is_null
66    }
67}
68
69// Decode implementations have been moved to the types module
70
71#[cfg(feature = "any")]
72impl<'r> From<OdbcValueRef<'r>> for crate::any::AnyValueRef<'r> {
73    fn from(value: OdbcValueRef<'r>) -> Self {
74        crate::any::AnyValueRef {
75            type_info: crate::any::AnyTypeInfo::from(value.type_info.clone()),
76            kind: crate::any::value::AnyValueRefKind::Odbc(value),
77        }
78    }
79}
80
81#[cfg(feature = "any")]
82impl From<OdbcValue> for crate::any::AnyValue {
83    fn from(value: OdbcValue) -> Self {
84        crate::any::AnyValue {
85            type_info: crate::any::AnyTypeInfo::from(value.type_info.clone()),
86            kind: crate::any::value::AnyValueKind::Odbc(value),
87        }
88    }
89}