Commit 6e5a9f2d authored by Benjamin Morel's avatar Benjamin Morel

Document MySQL error codes

parent 1a9812bd
...@@ -27,85 +27,148 @@ use function version_compare; ...@@ -27,85 +27,148 @@ use function version_compare;
*/ */
abstract class AbstractMySQLDriver implements ExceptionConverterDriver, VersionAwarePlatformDriver abstract class AbstractMySQLDriver implements ExceptionConverterDriver, VersionAwarePlatformDriver
{ {
/**#@+
* MySQL server error codes.
*
* @link https://dev.mysql.com/doc/refman/8.0/en/server-error-reference.html
*/
private const ER_DBACCESS_DENIED_ERROR = 1044;
private const ER_ACCESS_DENIED_ERROR = 1045;
private const ER_NO_DB_ERROR = 1046;
private const ER_BAD_NULL_ERROR = 1048;
private const ER_BAD_DB_ERROR = 1049;
private const ER_TABLE_EXISTS_ERROR = 1050;
private const ER_BAD_TABLE_ERROR = 1051;
private const ER_NON_UNIQ_ERROR = 1052;
private const ER_BAD_FIELD_ERROR = 1054;
private const ER_DUP_FIELDNAME = 1060;
private const ER_DUP_ENTRY = 1062;
private const ER_PARSE_ERROR = 1064;
private const ER_KILL_DENIED_ERROR = 1095;
private const ER_FIELD_SPECIFIED_TWICE = 1110;
private const ER_NULL_COLUMN_IN_INDEX = 1121;
private const ER_INVALID_USE_OF_NULL = 1138;
private const ER_TABLEACCESS_DENIED_ERROR = 1142;
private const ER_COLUMNACCESS_DENIED_ERROR = 1143;
private const ER_NO_SUCH_TABLE = 1146;
private const ER_SYNTAX_ERROR = 1149;
private const ER_WRONG_COLUMN_NAME = 1166;
private const ER_PRIMARY_CANT_HAVE_NULL = 1171;
private const ER_LOCK_WAIT_TIMEOUT = 1205;
private const ER_LOCK_DEADLOCK = 1213;
private const ER_NO_REFERENCED_ROW = 1216;
private const ER_ROW_IS_REFERENCED = 1217;
private const ER_SPECIFIC_ACCESS_DENIED_ERROR = 1227;
private const ER_SPATIAL_CANT_HAVE_NULL = 1252;
private const ER_WARN_NULL_TO_NOTNULL = 1263;
private const ER_WARN_DEPRECATED_SYNTAX = 1287;
private const ER_FPARSER_BAD_HEADER = 1341;
private const ER_FPARSER_EOF_IN_COMMENT = 1342;
private const ER_FPARSER_ERROR_IN_PARAMETER = 1343;
private const ER_FPARSER_EOF_IN_UNKNOWN_PARAMETER = 1344;
private const ER_NO_DEFAULT_FOR_FIELD = 1364;
private const ER_PROCACCESS_DENIED_ERROR = 1370;
private const ER_RESERVED_SYNTAX = 1382;
private const ER_CONNECT_TO_FOREIGN_DATA_SOURCE = 1429;
private const ER_ROW_IS_REFERENCED_2 = 1451;
private const ER_NO_REFERENCED_ROW_2 = 1452;
private const ER_PARTITION_REQUIRES_VALUES_ERROR = 1479;
private const ER_EVENT_DROP_FAILED = 1541;
private const ER_WARN_DEPRECATED_SYNTAX_WITH_VER = 1554;
private const ER_FOREIGN_DUPLICATE_KEY_OLD_UNUSED = 1557;
private const ER_NULL_IN_VALUES_LESS_THAN = 1566;
private const ER_DUP_ENTRY_AUTOINCREMENT_CASE = 1569;
private const ER_DUP_ENTRY_WITH_KEY_NAME = 1586;
private const ER_LOAD_DATA_INVALID_COLUMN = 1611;
private const ER_CONFLICT_FN_PARSE_ERROR = 1626;
private const ER_TRUNCATE_ILLEGAL_FK = 1701;
/**#@-*/
/**#@+
* MySQL client error codes.
*
* @link https://dev.mysql.com/doc/refman/8.0/en/client-error-reference.html
*/
private const CR_CONNECTION_ERROR = 2002;
private const CR_UNKNOWN_HOST = 2005;
/**#@-*/
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @link http://dev.mysql.com/doc/refman/5.7/en/error-messages-client.html
* @link http://dev.mysql.com/doc/refman/5.7/en/error-messages-server.html
*/ */
public function convertException(string $message, DriverExceptionInterface $exception) : DriverException public function convertException(string $message, DriverExceptionInterface $exception) : DriverException
{ {
switch ($exception->getCode()) { switch ($exception->getCode()) {
case 1213: case self::ER_LOCK_DEADLOCK:
return new Exception\DeadlockException($message, $exception); return new Exception\DeadlockException($message, $exception);
case 1205: case self::ER_LOCK_WAIT_TIMEOUT:
return new Exception\LockWaitTimeoutException($message, $exception); return new Exception\LockWaitTimeoutException($message, $exception);
case 1050: case self::ER_TABLE_EXISTS_ERROR:
return new Exception\TableExistsException($message, $exception); return new Exception\TableExistsException($message, $exception);
case 1051: case self::ER_BAD_TABLE_ERROR:
case 1146: case self::ER_NO_SUCH_TABLE:
return new Exception\TableNotFoundException($message, $exception); return new Exception\TableNotFoundException($message, $exception);
case 1216: case self::ER_NO_REFERENCED_ROW:
case 1217: case self::ER_ROW_IS_REFERENCED:
case 1451: case self::ER_ROW_IS_REFERENCED_2:
case 1452: case self::ER_NO_REFERENCED_ROW_2:
case 1701: case self::ER_TRUNCATE_ILLEGAL_FK:
return new Exception\ForeignKeyConstraintViolationException($message, $exception); return new Exception\ForeignKeyConstraintViolationException($message, $exception);
case 1062: case self::ER_DUP_ENTRY:
case 1557: case self::ER_FOREIGN_DUPLICATE_KEY_OLD_UNUSED:
case 1569: case self::ER_DUP_ENTRY_AUTOINCREMENT_CASE:
case 1586: case self::ER_DUP_ENTRY_WITH_KEY_NAME:
return new Exception\UniqueConstraintViolationException($message, $exception); return new Exception\UniqueConstraintViolationException($message, $exception);
case 1054: case self::ER_BAD_FIELD_ERROR:
case 1166: case self::ER_WRONG_COLUMN_NAME:
case 1611: case self::ER_LOAD_DATA_INVALID_COLUMN:
return new Exception\InvalidFieldNameException($message, $exception); return new Exception\InvalidFieldNameException($message, $exception);
case 1052: case self::ER_NON_UNIQ_ERROR:
case 1060: case self::ER_DUP_FIELDNAME:
case 1110: case self::ER_FIELD_SPECIFIED_TWICE:
return new Exception\NonUniqueFieldNameException($message, $exception); return new Exception\NonUniqueFieldNameException($message, $exception);
case 1064: case self::ER_PARSE_ERROR:
case 1149: case self::ER_SYNTAX_ERROR:
case 1287: case self::ER_WARN_DEPRECATED_SYNTAX:
case 1341: case self::ER_FPARSER_BAD_HEADER:
case 1342: case self::ER_FPARSER_EOF_IN_COMMENT:
case 1343: case self::ER_FPARSER_ERROR_IN_PARAMETER:
case 1344: case self::ER_FPARSER_EOF_IN_UNKNOWN_PARAMETER:
case 1382: case self::ER_RESERVED_SYNTAX:
case 1479: case self::ER_PARTITION_REQUIRES_VALUES_ERROR:
case 1541: case self::ER_EVENT_DROP_FAILED:
case 1554: case self::ER_WARN_DEPRECATED_SYNTAX_WITH_VER:
case 1626: case self::ER_CONFLICT_FN_PARSE_ERROR:
return new Exception\SyntaxErrorException($message, $exception); return new Exception\SyntaxErrorException($message, $exception);
case 1044: case self::ER_DBACCESS_DENIED_ERROR:
case 1045: case self::ER_ACCESS_DENIED_ERROR:
case 1046: case self::ER_NO_DB_ERROR:
case 1049: case self::ER_BAD_DB_ERROR:
case 1095: case self::ER_KILL_DENIED_ERROR:
case 1142: case self::ER_TABLEACCESS_DENIED_ERROR:
case 1143: case self::ER_COLUMNACCESS_DENIED_ERROR:
case 1227: case self::ER_SPECIFIC_ACCESS_DENIED_ERROR:
case 1370: case self::ER_PROCACCESS_DENIED_ERROR:
case 1429: case self::ER_CONNECT_TO_FOREIGN_DATA_SOURCE:
case 2002: case self::CR_CONNECTION_ERROR:
case 2005: case self::CR_UNKNOWN_HOST:
return new Exception\ConnectionException($message, $exception); return new Exception\ConnectionException($message, $exception);
case 1048: case self::ER_BAD_NULL_ERROR:
case 1121: case self::ER_NULL_COLUMN_IN_INDEX:
case 1138: case self::ER_INVALID_USE_OF_NULL:
case 1171: case self::ER_PRIMARY_CANT_HAVE_NULL:
case 1252: case self::ER_SPATIAL_CANT_HAVE_NULL:
case 1263: case self::ER_WARN_NULL_TO_NOTNULL:
case 1364: case self::ER_NO_DEFAULT_FOR_FIELD:
case 1566: case self::ER_NULL_IN_VALUES_LESS_THAN:
return new Exception\NotNullConstraintViolationException($message, $exception); return new Exception\NotNullConstraintViolationException($message, $exception);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment