| |
/// Create the counter with an initial value. Only use this if
|
| |
/// there isn't a counter row already.
|
| |
pub fn create_counter(&self, counter: i64) -> Result<(), DbError> {
|
| - |
let mut insert = self.prepare("INSERT INTO counter_test (counter) VALUES (:1)")?;
|
| - |
insert.stmt.bind((1, counter)).unwrap();
|
| + |
let sql = "INSERT INTO counter_test (counter) VALUES (:1)";
|
| + |
let mut insert = self.prepare(sql)?;
|
| + |
insert
|
| + |
.stmt
|
| + |
.bind((1, counter))
|
| + |
.map_err(|e| DbError::bind(sql, e))?;
|
| |
match insert.stmt.next() {
|
| |
Ok(_) => (),
|
| |
Err(e) => return Err(DbError::insert_counter(&insert.sql, e)),
|
| |
|
| |
/// Update the counter to have a new value.
|
| |
pub fn update_counter(&self, counter: i64) -> Result<(), DbError> {
|
| - |
let mut update = self.prepare("UPDATE counter_test SET counter = :1")?;
|
| - |
update.stmt.bind((1, counter)).unwrap();
|
| + |
let sql = "UPDATE counter_test SET counter = :1";
|
| + |
let mut update = self.prepare(sql)?;
|
| + |
update
|
| + |
.stmt
|
| + |
.bind((1, counter))
|
| + |
.map_err(|e| DbError::bind(sql, e))?;
|
| |
match update.stmt.next() {
|
| |
Ok(_) => (),
|
| |
Err(e) => return Err(DbError::update_counter(&update.sql, e)),
|