Skip to content

Commit 5b416ce

Browse files
committed
Added a quick test of different parameter types
1 parent 2b6cdf3 commit 5b416ce

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

src/postgres/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,12 @@ impl<'self> ToSql for &'self str {
525525
}
526526
}
527527

528+
impl ToSql for ~str {
529+
fn to_sql(&self) -> Option<~str> {
530+
Some(self.clone())
531+
}
532+
}
533+
528534
impl ToSql for Option<~str> {
529535
fn to_sql(&self) -> Option<~str> {
530536
self.clone()

src/postgres/test.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,29 @@ fn test_null() {
7171
Err::<(), ~str>(~"")
7272
};
7373
}
74+
75+
#[test]
76+
fn test_types() {
77+
let conn = chk!(PostgresConnection::new("postgres://postgres@localhost"));
78+
79+
do conn.in_transaction |conn| {
80+
chk!(conn.update(
81+
"CREATE TABLE foo (
82+
id INT PRIMARY KEY,
83+
str VARCHAR,
84+
float REAL
85+
)", []));
86+
chk!(conn.update("INSERT INTO foo (id, str, float)
87+
VALUES ($1, $2, $3), ($4, $5, $6)",
88+
params!(&101, & &"foobar", &10.5,
89+
&102, &None::<~str>, &None::<float>)));
90+
91+
let res = chk!(conn.query("SELECT str, float from foo ORDER BY id", []));
92+
assert_eq!(~"foobar", res.get(0).get::<~str>(0));
93+
assert_eq!(10.5, res.get(0).get::<float>(1));
94+
assert_eq!(None::<~str>, res.get(1).get::<Option<~str>>(0));
95+
assert_eq!(None::<float>, res.get(1).get::<Option<float>>(1));
96+
97+
Err::<(), ~str>(~"")
98+
};
99+
}

0 commit comments

Comments
 (0)