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
use crate::{
execute::execute,
handles::{Statement, StatementImpl},
parameter::StableCData,
CursorImpl, Error, ParameterRefCollection,
};
pub struct Prebound<'open_connection, Parameters> {
statement: StatementImpl<'open_connection>,
parameters: Parameters,
}
impl<'o, P> Prebound<'o, P>
where
P: ParameterMutCollection,
{
pub unsafe fn new(mut statement: StatementImpl<'o>, mut parameters: P) -> Result<Self, Error> {
statement.reset_parameters().into_result(&statement)?;
let paramset_size = parameters.parameter_set_size();
statement.set_paramset_size(paramset_size);
parameters.bind_parameters_to(&mut statement)?;
Ok(Self {
statement,
parameters,
})
}
pub fn execute(&mut self) -> Result<Option<CursorImpl<&mut StatementImpl<'o>>>, Error> {
unsafe { execute(&mut self.statement, None) }
}
pub fn params_mut(&mut self) -> &mut P::Mut {
self.parameters.as_mut()
}
}
pub unsafe trait ParameterMutCollection: ParameterRefCollection {
type Mut;
fn as_mut(&mut self) -> &mut Self::Mut;
}
unsafe impl<T> ParameterMutCollection for &mut T
where
T: StableCData,
for<'a> &'a mut T: ParameterRefCollection,
{
type Mut = T;
fn as_mut(&mut self) -> &mut T {
self
}
}
unsafe impl<T> ParameterMutCollection for Box<T>
where
T: StableCData,
Box<T>: ParameterRefCollection,
{
type Mut = T;
fn as_mut(&mut self) -> &mut T {
self
}
}