lunatic_sqlite_api/wire_format/bind_values/
host_api.rs1use anyhow::Result;
2use lunatic_common_api::IntoTrap;
3use sqlite::Statement;
4
5use super::{BindKey, BindPair, BindValue, SqliteError};
6
7impl BindPair {
8 pub fn bind(&self, statement: &mut Statement) -> Result<()> {
9 if let BindKey::Numeric(idx) = self.0 {
10 return match self.1.clone() {
11 BindValue::Null => statement.bind((idx, ())),
12 BindValue::Blob(b) => statement.bind((idx, &b[..])),
13 BindValue::Text(t) => statement.bind((idx, t.as_str())),
14 BindValue::Double(d) => statement.bind((idx, d)),
15 BindValue::Int(i) => statement.bind((idx, i as i64)),
16 BindValue::Int64(i) => statement.bind((idx, i)),
17 }
18 .or_trap("sqlite::bind::pair");
19 }
20 match self.1.clone() {
21 BindValue::Blob(b) => statement.bind(&[&b[..]][..]),
22 BindValue::Null => statement.bind(&[()][..]),
23 BindValue::Text(t) => statement.bind(&[t.as_str()][..]),
24 BindValue::Double(d) => statement.bind(&[d][..]),
25 BindValue::Int(i) => statement.bind(&[i as i64][..]),
26 BindValue::Int64(i) => statement.bind(&[i][..]),
27 }
28 .or_trap("sqlite::bind::single")
29 }
30}
31
32impl From<sqlite::Error> for SqliteError {
34 fn from(err: sqlite::Error) -> Self {
35 Self {
36 code: err.code.map(|code| code as u32),
37 message: err.message,
38 }
39 }
40}