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