mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-04-21 05:56:50 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
10
tests/mysql/setup-mariadb.sql
Normal file
10
tests/mysql/setup-mariadb.sql
Normal 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
|
||||
);
|
||||
Reference in New Issue
Block a user