Skip to content

Commit

Permalink
fix(mysql): don't use an arbitrary cfg for one test
Browse files Browse the repository at this point in the history
  • Loading branch information
abonander committed Aug 24, 2024
1 parent b5c218e commit 823261a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
20 changes: 20 additions & 0 deletions sqlx-mysql/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
// <https://dev.mysql.com/doc/mysql-errors/8.4/en/server-error-reference.html#error_er_innodb_autoextend_size_out_of_range
if self.0.sql_state.as_deref() == Some("23000") =>
{
ErrorKind::CheckViolation
}

_ => ErrorKind::Other,
}
}
Expand Down Expand Up @@ -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: <https://mariadb.com/kb/en/e4025/>
///
/// MySQL emits this code for a completely different error:
/// <https://dev.mysql.com/doc/mysql-errors/8.4/en/server-error-reference.html#error_er_innodb_autoextend_size_out_of_range>
///
/// You also check that SQLSTATE is `23000`.
pub const ER_CONSTRAINT_FAILED: u16 = 4025;
}
}
1 change: 0 additions & 1 deletion tests/mysql/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<MySql>().await?;
Expand Down

0 comments on commit 823261a

Please sign in to comment.