mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-23 00:39:20 +08:00
Test parameters binding
This commit is contained in:
parent
a1654e7ee9
commit
9b973d01b1
@ -709,6 +709,7 @@ pub enum StatementStatus {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
use crate::types::ToSql;
|
||||||
use crate::{Connection, Error, Result, NO_PARAMS};
|
use crate::{Connection, Error, Result, NO_PARAMS};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -991,4 +992,40 @@ mod test {
|
|||||||
stmt.bind_parameter(&1, 1).unwrap();
|
stmt.bind_parameter(&1, 1).unwrap();
|
||||||
assert_eq!(Some("SELECT 1"), stmt.expanded_sql());
|
assert_eq!(Some("SELECT 1"), stmt.expanded_sql());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_bind_parameters() {
|
||||||
|
let db = Connection::open_in_memory().unwrap();
|
||||||
|
// dynamic slice:
|
||||||
|
db.query_row(
|
||||||
|
"SELECT ?1, ?2, ?3",
|
||||||
|
&[&1u8 as &ToSql, &"one", &Some("one")],
|
||||||
|
|row| row.get::<_, u8>(0),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
// existing collection:
|
||||||
|
let data = vec![1, 2, 3];
|
||||||
|
db.query_row("SELECT ?1, ?2, ?3", &data, |row| row.get::<_, u8>(0))
|
||||||
|
.unwrap();
|
||||||
|
db.query_row("SELECT ?1, ?2, ?3", data.as_slice(), |row| {
|
||||||
|
row.get::<_, u8>(0)
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
db.query_row("SELECT ?1, ?2, ?3", data, |row| row.get::<_, u8>(0))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
use std::collections::BTreeSet;
|
||||||
|
let data: BTreeSet<String> = ["one", "two", "three"]
|
||||||
|
.into_iter()
|
||||||
|
.map(|s| s.to_string())
|
||||||
|
.collect();
|
||||||
|
db.query_row("SELECT ?1, ?2, ?3", &data, |row| row.get::<_, String>(0))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let data = [0; 3];
|
||||||
|
db.query_row("SELECT ?1, ?2, ?3", &data, |row| row.get::<_, u8>(0))
|
||||||
|
.unwrap();
|
||||||
|
db.query_row("SELECT ?1, ?2, ?3", data.iter(), |row| row.get::<_, u8>(0))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user