@@ -89,17 +89,23 @@ pub mod ffi;
89
89
90
90
pub mod access;
91
91
92
+ pub trait DatabaseUpdate {
93
+ fn update < ' db , ' s > ( & ' db mut self ,
94
+ stmt : & ' s mut PreparedStatement < ' s > ,
95
+ values : & [ & ToSql ] ) -> SqliteResult < uint > ;
96
+ }
97
+
92
98
93
- impl core:: DatabaseConnection {
99
+ impl DatabaseUpdate for core:: DatabaseConnection {
94
100
/// Execute a statement after binding any parameters.
95
101
///
96
102
/// When the statement is done, The [number of rows
97
103
/// modified][changes] is reported.
98
104
///
99
105
/// [changes]: http://www.sqlite.org/c3ref/changes.html
100
- pub fn update < ' db , ' s > ( & ' db mut self ,
101
- stmt : & ' s mut PreparedStatement < ' s > ,
102
- values : & [ & ToSql ] ) -> SqliteResult < uint > {
106
+ fn update < ' db , ' s > ( & ' db mut self ,
107
+ stmt : & ' s mut PreparedStatement < ' s > ,
108
+ values : & [ & ToSql ] ) -> SqliteResult < uint > {
103
109
let check = {
104
110
try!( bind_values ( stmt, values) ) ;
105
111
let mut results = stmt. execute ( ) ;
@@ -113,12 +119,20 @@ impl core::DatabaseConnection {
113
119
}
114
120
}
115
121
116
- impl < ' s > core:: PreparedStatement < ' s > {
122
+
123
+ pub trait Query < ' s > {
124
+ fn query( & ' s mut self ,
125
+ values : & [ & ToSql ] ,
126
+ each_row: |& mut ResultRow |: ' s -> SqliteResult <( ) >
127
+ ) -> SqliteResult <( ) >;
128
+ }
129
+
130
+ impl <' s > Query < ' s > for core:: PreparedStatement < ' s > {
117
131
/// Process rows from a query after binding parameters.
118
- pub fn query ( & ' s mut self ,
119
- values : & [ & ToSql ] ,
120
- each_row: |& mut ResultRow |: ' s -> SqliteResult <( ) >
121
- ) -> SqliteResult <( ) > {
132
+ fn query ( & ' s mut self ,
133
+ values : & [ & ToSql ] ,
134
+ each_row: |& mut ResultRow |: ' s -> SqliteResult <( ) >
135
+ ) -> SqliteResult <( ) > {
122
136
try!( bind_values ( self , values ) ) ;
123
137
let mut results = self . execute ( ) ;
124
138
loop {
@@ -140,15 +154,20 @@ fn bind_values<'db>(s: &'db mut PreparedStatement, values: &[&ToSql]) -> SqliteR
140
154
}
141
155
142
156
143
- impl < ' s , ' r > core:: ResultRow < ' s , ' r > {
144
- pub fn get < I : RowIndex + Show + Clone , T : FromSql > ( & mut self , idx : I ) -> T {
157
+ trait ResultRowAccess {
158
+ fn get < I : RowIndex + Show + Clone , T : FromSql > ( & mut self , idx: I ) -> T ;
159
+ fn get_opt < I : RowIndex , T : FromSql > ( & mut self , idx : I ) -> SqliteResult < T > ;
160
+ }
161
+
162
+ impl <' s , ' r > ResultRowAccess for core:: ResultRow < ' s , ' r > {
163
+ fn get < I : RowIndex + Show + Clone , T : FromSql > ( & mut self , idx: I ) -> T {
145
164
match self . get_opt ( idx. clone ( ) ) {
146
165
Ok ( ok ) => ok,
147
166
Err ( err) => fail!( "retrieving column { } : { } ", idx, err)
148
167
}
149
168
}
150
169
151
- pub fn get_opt < I : RowIndex , T : FromSql > ( & mut self , idx : I ) -> SqliteResult < T > {
170
+ fn get_opt<I: RowIndex, T: FromSql>(&mut self, idx: I) -> SqliteResult<T> {
152
171
match idx.idx(self) {
153
172
Some(idx) => FromSql::from_sql(self, idx),
154
173
None => Err(SQLITE_MISUSE)
@@ -237,6 +256,7 @@ pub enum ColumnType {
237
256
#[cfg(test)]
238
257
mod bind_tests {
239
258
use super::{DatabaseConnection, ResultSet};
259
+ use super::{ResultRowAccess};
240
260
use super::{SqliteResult};
241
261
242
262
#[test]
0 commit comments