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::*}; diff --git a/tests/sqlite/macros.rs b/tests/sqlite/macros.rs index 0ab4dd56bf..e9d7d6e094 100644 --- a/tests/sqlite/macros.rs +++ b/tests/sqlite/macros.rs @@ -359,3 +359,29 @@ 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(()) +} + +#[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 packages ( 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..bd09b17026 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 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) +); diff --git a/tests/sqlite/sqlite.db b/tests/sqlite/sqlite.db index e357615025..562747d33a 100644 Binary files a/tests/sqlite/sqlite.db and b/tests/sqlite/sqlite.db differ