Skip to content

Commit d82b781

Browse files
authored
test(sqlite): add regression test for ORDER BY + LIMIT nullability (#4223)
Covers the scenario from #4147 where ORDER BY + LIMIT routes data through an ephemeral sorter table. Verifies NOT NULL columns keep their constraint, and nullable columns stay nullable. This already passes on main (the 0.9 explain rewrite fixed it), but there was no test guarding against regression.
1 parent b77ba16 commit d82b781

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

tests/sqlite/describe.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,50 @@ async fn it_describes_table_order_by() -> anyhow::Result<()> {
591591
Ok(())
592592
}
593593

594+
// Regression test for https://github.com/launchbadge/sqlx/issues/4147
595+
// ORDER BY + LIMIT routes data through an ephemeral sorter table;
596+
// the NOT NULL constraint must survive the round-trip.
597+
#[sqlx_macros::test]
598+
async fn it_describes_order_by_with_limit() -> anyhow::Result<()> {
599+
let mut conn = new::<Sqlite>().await?;
600+
601+
let info = conn
602+
.describe("SELECT text FROM tweet ORDER BY id DESC LIMIT 10".into_sql_str())
603+
.await?;
604+
assert_eq!(info.column(0).type_info().name(), "TEXT");
605+
assert_eq!(
606+
info.nullable(0),
607+
Some(false),
608+
"NOT NULL column should stay NOT NULL with ORDER BY + LIMIT"
609+
);
610+
611+
let info = conn
612+
.describe("SELECT text, is_sent FROM tweet ORDER BY id DESC LIMIT 10000".into_sql_str())
613+
.await?;
614+
assert_eq!(
615+
info.nullable(0),
616+
Some(false),
617+
"text should be NOT NULL with ORDER BY DESC + large LIMIT"
618+
);
619+
assert_eq!(
620+
info.nullable(1),
621+
Some(false),
622+
"is_sent should be NOT NULL with ORDER BY DESC + large LIMIT"
623+
);
624+
625+
// nullable column must remain nullable
626+
let info = conn
627+
.describe("SELECT owner_id FROM tweet ORDER BY id DESC LIMIT 10".into_sql_str())
628+
.await?;
629+
assert_eq!(
630+
info.nullable(0),
631+
Some(true),
632+
"nullable column should stay nullable with ORDER BY + LIMIT"
633+
);
634+
635+
Ok(())
636+
}
637+
594638
#[sqlx_macros::test]
595639
async fn it_describes_union() -> anyhow::Result<()> {
596640
async fn assert_union_described(

0 commit comments

Comments
 (0)