From b2e3e52f47be9fc33dbe91b014ff66f1808ebca0 Mon Sep 17 00:00:00 2001 From: Joel Uckelman Date: Sat, 27 Jun 2026 15:55:05 +0100 Subject: [PATCH 01/10] Added INSERT ... RETURNING test. Should fail. --- tests/sqlite/macros.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/sqlite/macros.rs b/tests/sqlite/macros.rs index 0ab4dd56bf..c1f419559e 100644 --- a/tests/sqlite/macros.rs +++ b/tests/sqlite/macros.rs @@ -359,3 +359,14 @@ async fn test_column_override_exact_nullable() -> anyhow::Result<()> { } // we don't emit bind parameter typechecks for SQLite so testing the overrides is redundant + +#[sqlx_macros::test] +async fn test_returning_primary_key_is_not_nullable() -> anyhow::Result<()> { + let mut conn = new::().await?; + let id: i64 = + sqlx::query_scalar!(r#"INSERT INTO accounts ( name ) VALUES ( 'test' ) RETURNING id"#) + .fetch_one(&mut conn) + .await?; + assert!(id > 0); + Ok(()) +} From 596096c998992af894ea6c700b45edbc535d0ba1 Mon Sep 17 00:00:00 2001 From: Joel Uckelman Date: Sat, 27 Jun 2026 16:04:49 +0100 Subject: [PATCH 02/10] Weird, why is this needed now? --- sqlx-sqlite/src/types/time.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/sqlx-sqlite/src/types/time.rs b/sqlx-sqlite/src/types/time.rs index 0e0027882d..950f51544a 100644 --- a/sqlx-sqlite/src/types/time.rs +++ b/sqlx-sqlite/src/types/time.rs @@ -192,6 +192,7 @@ fn decode_datetime_from_text(value: &str) -> Option { None } +#[allow(deprecated)] mod formats { use time::format_description::BorrowedFormatItem::{Component, Literal, Optional}; use time::format_description::{modifier, BorrowedFormatItem, Component::*}; From 13e42b7a3965c62f584206d0f02757d65d99a8dc Mon Sep 17 00:00:00 2001 From: Joel Uckelman Date: Sat, 27 Jun 2026 17:38:57 +0100 Subject: [PATCH 03/10] This test should fail. --- tests/sqlite/macros.rs | 15 +++++++++++++++ tests/sqlite/setup.sql | 9 +++++++++ 2 files changed, 24 insertions(+) diff --git a/tests/sqlite/macros.rs b/tests/sqlite/macros.rs index c1f419559e..42e0b0868f 100644 --- a/tests/sqlite/macros.rs +++ b/tests/sqlite/macros.rs @@ -370,3 +370,18 @@ async fn test_returning_primary_key_is_not_nullable() -> anyhow::Result<()> { assert!(id > 0); Ok(()) } + +#[sqlx_macros::test] +async fn test_returning_with_foreign_key_is_not_nullable() -> anyhow::Result<()> { + let mut conn = new::().await?; + sqlx::query("INSERT INTO projects ( project_id ) VALUES ( 1 )") + .execute(&mut conn) + .await?; + let _id: i64 = sqlx::query_scalar!( + r#"INSERT INTO foo ( project_id ) VALUES ( 1 ) RETURNING package_id"# + ) + .fetch_one(&mut conn) + .await?; + + Ok(()) +} diff --git a/tests/sqlite/setup.sql b/tests/sqlite/setup.sql index 8f7d77c46d..70128ef930 100644 --- a/tests/sqlite/setup.sql +++ b/tests/sqlite/setup.sql @@ -35,3 +35,12 @@ CREATE TABLE products ( price NUMERIC, CONSTRAINT price_greater_than_zero CHECK (price > 0) ); +-- +CREATE TABLE projects ( + project_id INTEGER PRIMARY KEY +); +CREATE TABLE foo ( + package_id INTEGER PRIMARY KEY NOT NULL CHECK(package_id >= 0), + project_id INTEGER NOT NULL, + FOREIGN KEY(project_id) REFERENCES projects(project_id) +); From 0f166a4e6cb6e3d0c0e1935cbc9c442edbd148ce Mon Sep 17 00:00:00 2001 From: Joel Uckelman Date: Sat, 27 Jun 2026 17:59:33 +0100 Subject: [PATCH 04/10] Formatting. --- tests/sqlite/macros.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/sqlite/macros.rs b/tests/sqlite/macros.rs index 42e0b0868f..f32fea433f 100644 --- a/tests/sqlite/macros.rs +++ b/tests/sqlite/macros.rs @@ -377,11 +377,10 @@ async fn test_returning_with_foreign_key_is_not_nullable() -> anyhow::Result<()> sqlx::query("INSERT INTO projects ( project_id ) VALUES ( 1 )") .execute(&mut conn) .await?; - let _id: i64 = sqlx::query_scalar!( - r#"INSERT INTO foo ( project_id ) VALUES ( 1 ) RETURNING package_id"# - ) - .fetch_one(&mut conn) - .await?; + let _id: i64 = + sqlx::query_scalar!(r#"INSERT INTO foo ( project_id ) VALUES ( 1 ) RETURNING package_id"#) + .fetch_one(&mut conn) + .await?; Ok(()) } From ab21b00deac8b91e6a67bb5e84ce15adafd952ff Mon Sep 17 00:00:00 2001 From: Joel Uckelman Date: Sat, 27 Jun 2026 18:07:41 +0100 Subject: [PATCH 05/10] Formatting. --- tests/sqlite/macros.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/sqlite/macros.rs b/tests/sqlite/macros.rs index f32fea433f..021d10e430 100644 --- a/tests/sqlite/macros.rs +++ b/tests/sqlite/macros.rs @@ -379,8 +379,8 @@ async fn test_returning_with_foreign_key_is_not_nullable() -> anyhow::Result<()> .await?; let _id: i64 = sqlx::query_scalar!(r#"INSERT INTO foo ( project_id ) VALUES ( 1 ) RETURNING package_id"#) - .fetch_one(&mut conn) - .await?; + .fetch_one(&mut conn) + .await?; Ok(()) } From c4591d49fcc229d2aff720a188c0d3674c127e7c Mon Sep 17 00:00:00 2001 From: Joel Uckelman Date: Sat, 27 Jun 2026 23:25:28 +0100 Subject: [PATCH 06/10] Fixed typo. --- tests/sqlite/macros.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sqlite/macros.rs b/tests/sqlite/macros.rs index 021d10e430..0fd691466b 100644 --- a/tests/sqlite/macros.rs +++ b/tests/sqlite/macros.rs @@ -378,7 +378,7 @@ async fn test_returning_with_foreign_key_is_not_nullable() -> anyhow::Result<()> .execute(&mut conn) .await?; let _id: i64 = - sqlx::query_scalar!(r#"INSERT INTO foo ( project_id ) VALUES ( 1 ) RETURNING package_id"#) + sqlx::query_scalar!(r#"INSERT INTO packages ( project_id ) VALUES ( 1 ) RETURNING package_id"#) .fetch_one(&mut conn) .await?; From a332ee2a34707dd98aad35a89122d699f0b48a39 Mon Sep 17 00:00:00 2001 From: Joel Uckelman Date: Sat, 27 Jun 2026 23:27:15 +0100 Subject: [PATCH 07/10] Formatting. --- tests/sqlite/macros.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/sqlite/macros.rs b/tests/sqlite/macros.rs index 0fd691466b..9fd5008efe 100644 --- a/tests/sqlite/macros.rs +++ b/tests/sqlite/macros.rs @@ -377,10 +377,10 @@ async fn test_returning_with_foreign_key_is_not_nullable() -> anyhow::Result<()> sqlx::query("INSERT INTO projects ( project_id ) VALUES ( 1 )") .execute(&mut conn) .await?; - let _id: i64 = - sqlx::query_scalar!(r#"INSERT INTO packages ( project_id ) VALUES ( 1 ) RETURNING package_id"#) - .fetch_one(&mut conn) - .await?; + let _id: i64 = sqlx::query_scalar!( + r#"INSERT INTO packages ( project_id ) VALUES ( 1 ) RETURNING package_id"#) + .fetch_one(&mut conn) + .await?; Ok(()) } From 98eb7b240336cc09bf745f7dc10f4a7ad55bdc88 Mon Sep 17 00:00:00 2001 From: Joel Uckelman Date: Sat, 27 Jun 2026 23:31:14 +0100 Subject: [PATCH 08/10] Formatting. --- tests/sqlite/macros.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/sqlite/macros.rs b/tests/sqlite/macros.rs index 9fd5008efe..e9d7d6e094 100644 --- a/tests/sqlite/macros.rs +++ b/tests/sqlite/macros.rs @@ -378,7 +378,8 @@ async fn test_returning_with_foreign_key_is_not_nullable() -> anyhow::Result<()> .execute(&mut conn) .await?; let _id: i64 = sqlx::query_scalar!( - r#"INSERT INTO packages ( project_id ) VALUES ( 1 ) RETURNING package_id"#) + r#"INSERT INTO packages ( project_id ) VALUES ( 1 ) RETURNING package_id"# + ) .fetch_one(&mut conn) .await?; From c65f33e4b93905bb904aec29e2abe308a71060af Mon Sep 17 00:00:00 2001 From: Joel Uckelman Date: Tue, 30 Jun 2026 23:16:53 +0100 Subject: [PATCH 09/10] Fixed table name. --- tests/sqlite/setup.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sqlite/setup.sql b/tests/sqlite/setup.sql index 70128ef930..bd09b17026 100644 --- a/tests/sqlite/setup.sql +++ b/tests/sqlite/setup.sql @@ -39,7 +39,7 @@ CREATE TABLE products ( CREATE TABLE projects ( project_id INTEGER PRIMARY KEY ); -CREATE TABLE foo ( +CREATE TABLE packages ( package_id INTEGER PRIMARY KEY NOT NULL CHECK(package_id >= 0), project_id INTEGER NOT NULL, FOREIGN KEY(project_id) REFERENCES projects(project_id) From 6197578b626f8121092facf52b2792b10dba68cf Mon Sep 17 00:00:00 2001 From: Joel Uckelman Date: Tue, 30 Jun 2026 23:24:09 +0100 Subject: [PATCH 10/10] Updated test database. --- tests/sqlite/sqlite.db | Bin 36864 -> 36864 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/tests/sqlite/sqlite.db b/tests/sqlite/sqlite.db index e357615025e1e8b905d823110804fa9a422a92c9..562747d33a9a524784e2c1f0f986c53f4618ecc2 100644 GIT binary patch delta 391 zcmZozz|^pSX@ayM7Xt$WClJE``$QdMc`gRM-e0`@KNvW z#KX?5yRmUSSAAnRC%d?;EMqfcNn%n?YC&Rhc4B&JF^uMP4svx2aa9O$bnFXF2so?Dzso>`yqTm441 z2V_RQLP1e}R%&tyvLP^yU=<2({z0yu?tUO6H4ut56@pydT!UQwoLz%qW)vgKb7@9$ xfPL1;3h^1lo?@sG#T;OtnZvyXm4!m#Iq=QF-wBLW|o9M`~XXraK-=t delta 362 zcmZozz|^pSX@ayM9|HpeClJE`+e95>c|Hcccqv}~9}Jw_2N?L3_|Niw=6lVX&dbM> z#C?EAce9{?6SsRd2fMhUB4eXsNn%n?YJ72FPDOl4YHKNjx5aQ_M60D{aE1y8?_$?5zm99){loNVImijzO`Nr)p9#v3BooSTz)7A5ns@-JlIf6IT1 z|2Y2^{)Ir7^z+vXvNAJhmSkiWD*#cV0>}}9ESN&fm_kgLLW~$fT)?nl<$uAz|A+rO j|0kg3FJOTMp*PDboZy!LTFA%>B3M8KGl*aU+QzFL