mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-23 09:09:19 +08:00
commit
2ae8044c20
@ -809,7 +809,9 @@ mod test {
|
|||||||
|
|
||||||
assert!(!called.load(Ordering::Relaxed));
|
assert!(!called.load(Ordering::Relaxed));
|
||||||
let check = db
|
let check = db
|
||||||
.query_row("SELECT 1 FROM foo WHERE t = ?", &["bar"], |row| row.get::<_, i32>(0))
|
.query_row("SELECT 1 FROM foo WHERE t = ?", &["bar"], |row| {
|
||||||
|
row.get::<_, i32>(0)
|
||||||
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(1, check);
|
assert_eq!(1, check);
|
||||||
|
|
||||||
@ -845,7 +847,9 @@ mod test {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let check = db
|
let check = db
|
||||||
.query_row("SELECT 1 FROM foo WHERE t = ?", &["bar"], |row| row.get::<_, i32>(0))
|
.query_row("SELECT 1 FROM foo WHERE t = ?", &["bar"], |row| {
|
||||||
|
row.get::<_, i32>(0)
|
||||||
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(1, check);
|
assert_eq!(1, check);
|
||||||
}
|
}
|
||||||
|
@ -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