diff --git a/src/postgres/lib.rs b/src/postgres/lib.rs index 3efdfd0f..9dc1524f 100644 --- a/src/postgres/lib.rs +++ b/src/postgres/lib.rs @@ -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() diff --git a/src/postgres/test.rs b/src/postgres/test.rs index 60afbe2a..65f2a6a6 100644 --- a/src/postgres/test.rs +++ b/src/postgres/test.rs @@ -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::))); + + 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::(1)); + assert_eq!(None::<~str>, res.get(1).get::>(0)); + assert_eq!(None::, res.get(1).get::>(1)); + + Err::<(), ~str>(~"") + }; +}