From a9c20d966bab3d9a0ec9992c039ff9937410b4de Mon Sep 17 00:00:00 2001 From: lovasoa Date: Sun, 7 Sep 2025 21:32:02 +0200 Subject: [PATCH 1/4] add support for the uuid type on the Any database --- sqlx-core/src/any/types.rs | 8 ++++++++ tests/any/any.rs | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/sqlx-core/src/any/types.rs b/sqlx-core/src/any/types.rs index 0a35115def..6236e83ab0 100644 --- a/sqlx-core/src/any/types.rs +++ b/sqlx-core/src/any/types.rs @@ -151,3 +151,11 @@ mod decimal_types { impl_any_encode!(Decimal); impl_any_decode!(Decimal); } + +#[cfg(feature = "uuid")] +mod uuid_types { + use uuid::Uuid; + impl_any_type!(Uuid); + impl_any_encode!(Uuid); + impl_any_decode!(Uuid); +} diff --git a/tests/any/any.rs b/tests/any/any.rs index a753b703a1..633f509ef4 100644 --- a/tests/any/any.rs +++ b/tests/any/any.rs @@ -112,6 +112,23 @@ async fn it_has_json() -> anyhow::Result<()> { Ok(()) } +#[cfg(feature = "uuid")] +#[sqlx_macros::test] +async fn it_has_uuid() -> anyhow::Result<()> { + use sqlx_oldapi::types::Uuid; + #[cfg(feature = "sqlite")] + let sql = "CAST('123e4567-e89b-12d3-a456-426614174000' AS TEXT)"; + #[cfg(feature = "mssql")] + let sql = "CONVERT(uniqueidentifier, '123e4567-e89b-12d3-a456-426614174000')"; + #[cfg(feature = "postgres")] + let sql = "CAST('123e4567-e89b-12d3-a456-426614174000' AS UUID)"; + assert_eq!( + Uuid::parse_str("123e4567-e89b-12d3-a456-426614174000")?, + get_val::(sql).await? + ); + Ok(()) +} + #[sqlx_macros::test] async fn it_pings() -> anyhow::Result<()> { let mut conn = new::().await?; From dc88ab9ae9d2e9e94dddecc174ee027a15bf36f2 Mon Sep 17 00:00:00 2001 From: lovasoa Date: Sun, 7 Sep 2025 22:45:10 +0200 Subject: [PATCH 2/4] Fix UUID test for MySQL The previous test used the wrong SQL for MySQL. This commit corrects it. --- tests/any/any.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/any/any.rs b/tests/any/any.rs index 633f509ef4..1325445d15 100644 --- a/tests/any/any.rs +++ b/tests/any/any.rs @@ -117,11 +117,13 @@ async fn it_has_json() -> anyhow::Result<()> { async fn it_has_uuid() -> anyhow::Result<()> { use sqlx_oldapi::types::Uuid; #[cfg(feature = "sqlite")] - let sql = "CAST('123e4567-e89b-12d3-a456-426614174000' AS TEXT)"; + let sql = "x'123e4567e89b12d3a456426614174000'"; #[cfg(feature = "mssql")] let sql = "CONVERT(uniqueidentifier, '123e4567-e89b-12d3-a456-426614174000')"; #[cfg(feature = "postgres")] let sql = "CAST('123e4567-e89b-12d3-a456-426614174000' AS UUID)"; + #[cfg(feature = "mysql")] + let sql = "UUID_TO_BIN('123e4567-e89b-12d3-a456-426614174000')"; assert_eq!( Uuid::parse_str("123e4567-e89b-12d3-a456-426614174000")?, get_val::(sql).await? From 4f5d3a47a55274d7e3be9d9f17cb7ecdccac9a91 Mon Sep 17 00:00:00 2001 From: lovasoa Date: Sun, 7 Sep 2025 22:57:19 +0200 Subject: [PATCH 3/4] Fix UUID test for various databases --- tests/any/any.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/tests/any/any.rs b/tests/any/any.rs index 1325445d15..06397f596d 100644 --- a/tests/any/any.rs +++ b/tests/any/any.rs @@ -116,17 +116,16 @@ async fn it_has_json() -> anyhow::Result<()> { #[sqlx_macros::test] async fn it_has_uuid() -> anyhow::Result<()> { use sqlx_oldapi::types::Uuid; - #[cfg(feature = "sqlite")] - let sql = "x'123e4567e89b12d3a456426614174000'"; - #[cfg(feature = "mssql")] - let sql = "CONVERT(uniqueidentifier, '123e4567-e89b-12d3-a456-426614174000')"; - #[cfg(feature = "postgres")] - let sql = "CAST('123e4567-e89b-12d3-a456-426614174000' AS UUID)"; - #[cfg(feature = "mysql")] - let sql = "UUID_TO_BIN('123e4567-e89b-12d3-a456-426614174000')"; assert_eq!( Uuid::parse_str("123e4567-e89b-12d3-a456-426614174000")?, - get_val::(sql).await? + get_val::(if cfg!(feature = "mssql") { + "CONVERT(uniqueidentifier, '123e4567-e89b-12d3-a456-426614174000')²" + } else if cfg!(feature = "postgres") { + "'123e4567-e89b-12d3-a456-426614174000'::uuid" + } else { + "x'123e4567e89b12d3a456426614174000'" + }) + .await? ); Ok(()) } From 1f05eb074705ef2ab431408eaf8e29dce3fa3470 Mon Sep 17 00:00:00 2001 From: lovasoa Date: Sun, 7 Sep 2025 23:10:52 +0200 Subject: [PATCH 4/4] Fix MSSQL UUID test Fix MSSQL UUID test The MSSQL UUID test was failing due to an incorrect query string. This commit removes the extra character. --- tests/any/any.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/any/any.rs b/tests/any/any.rs index 06397f596d..ed14cf3354 100644 --- a/tests/any/any.rs +++ b/tests/any/any.rs @@ -119,7 +119,7 @@ async fn it_has_uuid() -> anyhow::Result<()> { assert_eq!( Uuid::parse_str("123e4567-e89b-12d3-a456-426614174000")?, get_val::(if cfg!(feature = "mssql") { - "CONVERT(uniqueidentifier, '123e4567-e89b-12d3-a456-426614174000')²" + "CONVERT(uniqueidentifier, '123e4567-e89b-12d3-a456-426614174000')" } else if cfg!(feature = "postgres") { "'123e4567-e89b-12d3-a456-426614174000'::uuid" } else {