Skip to content

Commit 823261a

Browse files
committed
fix(mysql): don't use an arbitrary cfg for one test
1 parent b5c218e commit 823261a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

sqlx-mysql/src/error.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ impl DatabaseError for MySqlDatabaseError {
100100

101101
error_codes::ER_CHECK_CONSTRAINT_VIOLATED => ErrorKind::CheckViolation,
102102

103+
// https://mariadb.com/kb/en/e4025/
104+
error_codes::mariadb::ER_CONSTRAINT_FAILED
105+
// MySQL uses this code for a completely different error,
106+
// but we can differentiate by SQLSTATE:
107+
// <https://dev.mysql.com/doc/mysql-errors/8.4/en/server-error-reference.html#error_er_innodb_autoextend_size_out_of_range
108+
if self.0.sql_state.as_deref() == Some("23000") =>
109+
{
110+
ErrorKind::CheckViolation
111+
}
112+
103113
_ => ErrorKind::Other,
104114
}
105115
}
@@ -154,4 +164,14 @@ pub(crate) mod error_codes {
154164
///
155165
/// Only available after 8.0.16.
156166
pub const ER_CHECK_CONSTRAINT_VIOLATED: u16 = 3819;
167+
168+
pub(crate) mod mariadb {
169+
/// Error code emitted by MariaDB for constraint errors: <https://mariadb.com/kb/en/e4025/>
170+
///
171+
/// MySQL emits this code for a completely different error:
172+
/// <https://dev.mysql.com/doc/mysql-errors/8.4/en/server-error-reference.html#error_er_innodb_autoextend_size_out_of_range>
173+
///
174+
/// You also check that SQLSTATE is `23000`.
175+
pub const ER_CONSTRAINT_FAILED: u16 = 4025;
176+
}
157177
}

tests/mysql/error.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ async fn it_fails_with_not_null_violation() -> anyhow::Result<()> {
5757
Ok(())
5858
}
5959

60-
#[cfg(mysql_8)]
6160
#[sqlx_macros::test]
6261
async fn it_fails_with_check_violation() -> anyhow::Result<()> {
6362
let mut conn = new::<MySql>().await?;

0 commit comments

Comments
 (0)