|
1 | 1 | use chrono_04::{DateTime, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc}; |
2 | | -use tokio_postgres::types::{Date, Timestamp}; |
| 2 | +use std::fmt; |
| 3 | +use tokio_postgres::types::{Date, FromSqlOwned, Timestamp}; |
| 4 | +use tokio_postgres::Client; |
3 | 5 |
|
| 6 | +use crate::connect; |
4 | 7 | use crate::types::test_type; |
5 | 8 |
|
6 | 9 | #[tokio::test] |
@@ -153,3 +156,33 @@ async fn test_time_params() { |
153 | 156 | ) |
154 | 157 | .await; |
155 | 158 | } |
| 159 | + |
| 160 | +#[tokio::test] |
| 161 | +async fn test_special_params_without_wrapper() { |
| 162 | + async fn assert_overflows<T>(client: &mut Client, val: &str, sql_type: &str) |
| 163 | + where |
| 164 | + T: FromSqlOwned + fmt::Debug, |
| 165 | + { |
| 166 | + let err = client |
| 167 | + .query_one(&*format!("SELECT {}::{}", val, sql_type), &[]) |
| 168 | + .await |
| 169 | + .unwrap() |
| 170 | + .try_get::<_, T>(0) |
| 171 | + .unwrap_err(); |
| 172 | + assert_eq!( |
| 173 | + err.to_string(), |
| 174 | + "error deserializing column 0: value too large to decode" |
| 175 | + ); |
| 176 | + } |
| 177 | + |
| 178 | + let mut client = connect("user=postgres").await; |
| 179 | + |
| 180 | + assert_overflows::<DateTime<Utc>>(&mut client, "'-infinity'", "timestamptz").await; |
| 181 | + assert_overflows::<DateTime<Utc>>(&mut client, "'infinity'", "timestamptz").await; |
| 182 | + |
| 183 | + assert_overflows::<NaiveDateTime>(&mut client, "'-infinity'", "timestamp").await; |
| 184 | + assert_overflows::<NaiveDateTime>(&mut client, "'infinity'", "timestamp").await; |
| 185 | + |
| 186 | + assert_overflows::<NaiveDate>(&mut client, "'-infinity'", "date").await; |
| 187 | + assert_overflows::<NaiveDate>(&mut client, "'infinity'", "date").await; |
| 188 | +} |
0 commit comments