From 3961dc39eba5f9dc68ba6b65e2b0d5394ccc9715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orvar=20Segerstr=C3=B6m?= Date: Tue, 25 Oct 2022 14:38:50 +0200 Subject: [PATCH] Add more tests to sqlite/describe --- tests/sqlite/describe.rs | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/sqlite/describe.rs b/tests/sqlite/describe.rs index ffd088badc..58015d80e1 100644 --- a/tests/sqlite/describe.rs +++ b/tests/sqlite/describe.rs @@ -469,3 +469,52 @@ async fn it_describes_union() -> anyhow::Result<()> { Ok(()) } + +#[sqlx_macros::test] +async fn it_describes_select_with_order_and_limit() -> anyhow::Result<()> { + let mut conn = new::().await?; + + let d = conn + .describe( + r#" + SELECT accounts.name FROM accounts + ORDER BY accounts.name ASC + LIMIT 1 + "#, + ) + .await?; + + assert_eq!(d.column(0).type_info().name(), "TEXT"); + assert_eq!(d.nullable(0), Some(false)); + + Ok(()) +} + +#[sqlx_macros::test] +async fn it_describes_non_nullable_columns() -> anyhow::Result<()> { + let mut conn = new::().await?; + + conn.execute( + r#" + create temp table _temp_primary_keys ( + id integer primary key autoincrement, + email text not null unique, + password_hash text not null + ); + "#, + ) + .await?; + + let d = conn.describe("SELECT * FROM _temp_primary_keys").await?; + + assert_eq!(d.column(0).type_info().name(), "INTEGER"); + assert_eq!(d.nullable(0), Some(false)); + + assert_eq!(d.column(1).type_info().name(), "TEXT"); + assert_eq!(d.nullable(1), Some(false)); + + assert_eq!(d.column(2).type_info().name(), "TEXT"); + assert_eq!(d.nullable(2), Some(false)); + + Ok(()) +}