Mercurial > p > mysql-python > mysqldb-2
diff _mysql_exceptions.py @ 8:fa8974a41c76 MySQLdb
New error handling code, plus some small fixes from 1.2
author | adustman |
---|---|
date | Sun, 11 Feb 2007 21:36:29 +0000 |
parents | e48810735f11 |
children |
line wrap: on
line diff
--- a/_mysql_exceptions.py Sun Feb 11 07:40:50 2007 +0000 +++ b/_mysql_exceptions.py Sun Feb 11 21:36:29 2007 +0000 @@ -6,6 +6,7 @@ """ from exceptions import Exception, StandardError, Warning +from MySQLdb.constants import ER class MySQLError(StandardError): @@ -80,4 +81,23 @@ has transactions turned off.""" -del Exception, StandardError +error_map = {} + +def _map_error(exc, *errors): + for error in errors: + error_map[error] = exc + +_map_error(ProgrammingError, ER.DB_CREATE_EXISTS, ER.SYNTAX_ERROR, + ER.PARSE_ERROR, ER.NO_SUCH_TABLE, ER.WRONG_DB_NAME, ER.WRONG_TABLE_NAME, + ER.FIELD_SPECIFIED_TWICE, ER.INVALID_GROUP_FUNC_USE, ER.UNSUPPORTED_EXTENSION, + ER.TABLE_MUST_HAVE_COLUMNS, ER.CANT_DO_THIS_DURING_AN_TRANSACTION) +_map_error(DataError, ER.WARN_DATA_TRUNCATED, ER.WARN_NULL_TO_NOTNULL, + ER.WARN_DATA_OUT_OF_RANGE, ER.NO_DEFAULT, ER.PRIMARY_CANT_HAVE_NULL, + ER.DATA_TOO_LONG, ER.DATETIME_FUNCTION_OVERFLOW) +_map_error(IntegrityError, ER.DUP_ENTRY, ER.NO_REFERENCED_ROW, + ER.NO_REFERENCED_ROW_2, ER.ROW_IS_REFERENCED, ER.ROW_IS_REFERENCED_2, + ER.CANNOT_ADD_FOREIGN) +_map_error(NotSupportedError, ER.WARNING_NOT_COMPLETE_ROLLBACK, ER.NOT_SUPPORTED_YET, + ER.FEATURE_DISABLED, ER.UNKNOWN_STORAGE_ENGINE) + +del Exception, StandardError, _map_error, ER