breaking(mysql): assume all non-binary collations compatible with str (#3924)

cc https://github.com/launchbadge/sqlx/pull/3400#issuecomment-3041035104

comment in `sqlx-mysql/src/collation.rs` for explanation

fixes #3200
fixes #3387
fixes #3390
fixes #3409
This commit is contained in:
Austin Bonander
2025-07-08 00:39:46 -07:00
committed by GitHub
parent 469f22788e
commit a3aa942a78
22 changed files with 248 additions and 1029 deletions

View File

@@ -555,4 +555,34 @@ async fn test_from_row_json_try_from_attr() -> anyhow::Result<()> {
Ok(())
}
#[cfg(all(mariadb, not(mariadb = "10_6"), feature = "time"))]
#[sqlx_macros::test]
async fn test_uuid_is_compatible_mariadb() -> anyhow::Result<()> {
use sqlx::types::time::OffsetDateTime;
use sqlx::types::Uuid;
struct Tweet {
id: Uuid,
text: String,
created_at: OffsetDateTime,
owner_id: Option<Uuid>,
}
let mut conn = new::<MySql>().await?;
sqlx::query!("INSERT INTO tweet_with_uuid(text) VALUES ('Hello, world!')")
.execute(&mut conn)
.await?;
let tweets: Vec<Tweet> = sqlx::query_as!(Tweet, "SELECT * FROM tweet_with_uuid")
.fetch_all(&mut conn)
.await?;
assert_eq!(tweets.len(), 1);
assert_eq!(tweets[0].text, "Hello, world!");
Ok(())
}
// we don't emit bind parameter type-checks for MySQL so testing the overrides is redundant

View File

@@ -605,3 +605,34 @@ async fn select_statement_count(conn: &mut MySqlConnection) -> Result<i64, sqlx:
.fetch_one(conn)
.await
}
#[sqlx_macros::test]
async fn issue_3200() -> anyhow::Result<()> {
let mut conn = new::<MySql>().await?;
sqlx::raw_sql(
"\
CREATE TABLE IF NOT EXISTS users
(
`id` BIGINT AUTO_INCREMENT,
`username` VARCHAR(128) NOT NULL,
PRIMARY KEY (id)
);
",
)
.execute(&mut conn)
.await?;
let result = sqlx::raw_sql(
"\
SET @myvar := 'test@test.com';
select id from users where username = @myvar;
",
)
.fetch_optional(&mut conn)
.await?;
assert!(result.is_none(), "{result:?}");
Ok(())
}

View File

@@ -0,0 +1,10 @@
-- additional SQL to execute for MariaDB databases
CREATE TABLE tweet_with_uuid
(
-- UUID is only a bespoke datatype in MariaDB.
id UUID PRIMARY KEY DEFAULT UUID(),
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
text TEXT NOT NULL,
owner_id UUID
);