Skip to content

Commit 2c32c54

Browse files
committed
Add test for Postgres prepared statement types
see #983
1 parent 88e55aa commit 2c32c54

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/webserver/database/sql_to_json.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,42 @@ mod tests {
220220
Ok(())
221221
}
222222

223+
/// Postgres encodes values differently in prepared statements and in "simple" queries
224+
/// <https://www.postgresql.org/docs/9.1/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY>
225+
#[actix_web::test]
226+
async fn test_postgres_prepared_types() -> anyhow::Result<()> {
227+
let Some(db_url) = db_specific_test("postgres") else {
228+
return Ok(());
229+
};
230+
let mut c = sqlx::AnyConnection::connect(&db_url).await?;
231+
let row = sqlx::query(
232+
"SELECT
233+
'2024-03-14'::DATE as date,
234+
'13:14:15'::TIME as time,
235+
'2024-03-14 13:14:15+02:00'::TIMESTAMPTZ as timestamptz,
236+
INTERVAL '-01:02:03' as time_interval,
237+
'{\"key\": \"value\"}'::JSON as json,
238+
1234.56::MONEY as money_val
239+
where $1",
240+
)
241+
.bind(true)
242+
.fetch_one(&mut c)
243+
.await?;
244+
245+
expect_json_object_equal(
246+
&row_to_json(&row),
247+
&serde_json::json!({
248+
"date": "2024-03-14",
249+
"time": "13:14:15",
250+
"timestamptz": "2024-03-14T11:14:15+00:00",
251+
"time_interval": "-01:02:03",
252+
"json": {"key": "value"},
253+
"money_val": "" // TODO: fix this bug: https://github.com/sqlpage/SQLPage/issues/983
254+
}),
255+
);
256+
Ok(())
257+
}
258+
223259
#[actix_web::test]
224260
async fn test_mysql_types() -> anyhow::Result<()> {
225261
let db_url = db_specific_test("mysql").or_else(|| db_specific_test("mariadb"));

0 commit comments

Comments
 (0)