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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
use {ffi, Return, Result, Raii, Handle, Statement};
use super::types::OdbcType;
use std::cmp::{max};
impl<'a, 'b, S, R> Statement<'a, 'b, S, R> {
pub fn bind_parameter<'c, T>(
mut self,
parameter_index: u16,
value: &'c T,
) -> Result<Statement<'a, 'c, S, R>>
where
T: OdbcType<'c>,
T: ?Sized,
'b: 'c,
{
if parameter_index as usize >= self.param_ind_buffers.len() {
let new_size: usize = max(parameter_index as usize + 1, self.param_ind_buffers.len());
self.param_ind_buffers.resize(new_size, 0);
}
self.param_ind_buffers[parameter_index as usize] = value.column_size() as ffi::SQLLEN;
self.raii
.bind_input_parameter(parameter_index, value, &mut self.param_ind_buffers[parameter_index as usize])
.into_result(&self)?;
Ok(self)
}
pub fn reset_parameters(mut self) -> Result<Statement<'a, 'a, S, R>> {
self.param_ind_buffers.clear();
self.raii.reset_parameters().into_result(&mut self)?;
Ok(Statement::with_raii(self.raii))
}
}
impl Raii<ffi::Stmt> {
fn bind_input_parameter<'c, T>(&mut self, parameter_index: u16, value: &'c T, str_len_or_ind_ptr: & mut ffi::SQLLEN) -> Return<()>
where
T: OdbcType<'c>,
T: ?Sized,
{
match unsafe {
ffi::SQLBindParameter(
self.handle(),
parameter_index,
ffi::SQL_PARAM_INPUT,
T::c_data_type(),
T::sql_data_type(),
value.column_size(),
value.decimal_digits(),
value.value_ptr(),
0, str_len_or_ind_ptr as *mut ffi::SQLLEN, )
} {
ffi::SQL_SUCCESS => Return::Success(()),
ffi::SQL_SUCCESS_WITH_INFO => Return::SuccessWithInfo(()),
ffi::SQL_ERROR => Return::Error,
r => panic!("Unexpected return from SQLBindParameter: {:?}", r),
}
}
fn reset_parameters(&mut self) -> Return<()> {
match unsafe { ffi::SQLFreeStmt(self.handle(), ffi::SQL_RESET_PARAMS) } {
ffi::SQL_SUCCESS => Return::Success(()),
ffi::SQL_SUCCESS_WITH_INFO => Return::SuccessWithInfo(()),
ffi::SQL_ERROR => Return::Error,
r => panic!("SQLFreeStmt returned unexpected result: {:?}", r),
}
}
}