diff --git a/sqlx-mysql/src/error.rs b/sqlx-mysql/src/error.rs index 89c6df47..e7363399 100644 --- a/sqlx-mysql/src/error.rs +++ b/sqlx-mysql/src/error.rs @@ -100,6 +100,16 @@ impl DatabaseError for MySqlDatabaseError { error_codes::ER_CHECK_CONSTRAINT_VIOLATED => ErrorKind::CheckViolation, + // https://mariadb.com/kb/en/e4025/ + error_codes::mariadb::ER_CONSTRAINT_FAILED + // MySQL uses this code for a completely different error, + // but we can differentiate by SQLSTATE: + // + { + ErrorKind::CheckViolation + } + _ => ErrorKind::Other, } } @@ -154,4 +164,14 @@ pub(crate) mod error_codes { /// /// Only available after 8.0.16. pub const ER_CHECK_CONSTRAINT_VIOLATED: u16 = 3819; + + pub(crate) mod mariadb { + /// Error code emitted by MariaDB for constraint errors: + /// + /// MySQL emits this code for a completely different error: + /// + /// + /// You also check that SQLSTATE is `23000`. + pub const ER_CONSTRAINT_FAILED: u16 = 4025; + } } diff --git a/tests/mysql/error.rs b/tests/mysql/error.rs index bb174e5e..7c84266c 100644 --- a/tests/mysql/error.rs +++ b/tests/mysql/error.rs @@ -57,7 +57,6 @@ async fn it_fails_with_not_null_violation() -> anyhow::Result<()> { Ok(()) } -#[cfg(mysql_8)] #[sqlx_macros::test] async fn it_fails_with_check_violation() -> anyhow::Result<()> { let mut conn = new::().await?;