File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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]
6261async fn it_fails_with_check_violation ( ) -> anyhow:: Result < ( ) > {
6362 let mut conn = new :: < MySql > ( ) . await ?;
You can’t perform that action at this time.
0 commit comments