1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! Module contains trait implementations for `CStr` and `CString`.

use std::ffi::{c_void, CStr, CString};

use odbc_sys::{CDataType, NTS};

use crate::{
    handles::{CData, HasDataType},
    parameter::InputParameter,
    DataType,
};

unsafe impl CData for CStr {
    fn cdata_type(&self) -> CDataType {
        CDataType::Char
    }

    fn indicator_ptr(&self) -> *const isize {
        &NTS as *const isize
    }

    fn value_ptr(&self) -> *const c_void {
        self.as_ptr() as *const c_void
    }

    fn buffer_length(&self) -> isize {
        0
    }
}

impl HasDataType for CStr {
    fn data_type(&self) -> DataType {
        DataType::Varchar {
            length: self.to_bytes().len(),
        }
    }
}

unsafe impl InputParameter for CStr {}

unsafe impl CData for CString {
    fn cdata_type(&self) -> CDataType {
        CDataType::Char
    }

    fn indicator_ptr(&self) -> *const isize {
        &NTS as *const isize
    }

    fn value_ptr(&self) -> *const c_void {
        self.as_ptr() as *const c_void
    }

    fn buffer_length(&self) -> isize {
        0
    }
}

impl HasDataType for CString {
    fn data_type(&self) -> DataType {
        DataType::Varchar {
            length: self.as_bytes().len(),
        }
    }
}

unsafe impl InputParameter for CString {}