Added a quick test of different parameter types

This commit is contained in:
Steven Fackler
2013-08-17 22:42:12 -04:00
parent 2b6cdf3b9a
commit 5b416ce994
2 changed files with 32 additions and 0 deletions

View File

@@ -525,6 +525,12 @@ impl<'self> ToSql for &'self str {
}
}
impl ToSql for ~str {
fn to_sql(&self) -> Option<~str> {
Some(self.clone())
}
}
impl ToSql for Option<~str> {
fn to_sql(&self) -> Option<~str> {
self.clone()

View File

@@ -71,3 +71,29 @@ fn test_null() {
Err::<(), ~str>(~"")
};
}
#[test]
fn test_types() {
let conn = chk!(PostgresConnection::new("postgres://postgres@localhost"));
do conn.in_transaction |conn| {
chk!(conn.update(
"CREATE TABLE foo (
id INT PRIMARY KEY,
str VARCHAR,
float REAL
)", []));
chk!(conn.update("INSERT INTO foo (id, str, float)
VALUES ($1, $2, $3), ($4, $5, $6)",
params!(&101, & &"foobar", &10.5,
&102, &None::<~str>, &None::<float>)));
let res = chk!(conn.query("SELECT str, float from foo ORDER BY id", []));
assert_eq!(~"foobar", res.get(0).get::<~str>(0));
assert_eq!(10.5, res.get(0).get::<float>(1));
assert_eq!(None::<~str>, res.get(1).get::<Option<~str>>(0));
assert_eq!(None::<float>, res.get(1).get::<Option<float>>(1));
Err::<(), ~str>(~"")
};
}