Mercurial > p > mysql-python > mysqldb-2
comparison _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 |
comparison
equal
deleted
inserted
replaced
7:b1e508854b27 | 8:fa8974a41c76 |
---|---|
4 | 4 |
5 http://www.python.org/topics/database/DatabaseAPI-2.0.html | 5 http://www.python.org/topics/database/DatabaseAPI-2.0.html |
6 """ | 6 """ |
7 | 7 |
8 from exceptions import Exception, StandardError, Warning | 8 from exceptions import Exception, StandardError, Warning |
9 from MySQLdb.constants import ER | |
9 | 10 |
10 class MySQLError(StandardError): | 11 class MySQLError(StandardError): |
11 | 12 |
12 """Exception related to operation with MySQL.""" | 13 """Exception related to operation with MySQL.""" |
13 | 14 |
78 which is not supported by the database, e.g. requesting a | 79 which is not supported by the database, e.g. requesting a |
79 .rollback() on a connection that does not support transaction or | 80 .rollback() on a connection that does not support transaction or |
80 has transactions turned off.""" | 81 has transactions turned off.""" |
81 | 82 |
82 | 83 |
83 del Exception, StandardError | 84 error_map = {} |
85 | |
86 def _map_error(exc, *errors): | |
87 for error in errors: | |
88 error_map[error] = exc | |
89 | |
90 _map_error(ProgrammingError, ER.DB_CREATE_EXISTS, ER.SYNTAX_ERROR, | |
91 ER.PARSE_ERROR, ER.NO_SUCH_TABLE, ER.WRONG_DB_NAME, ER.WRONG_TABLE_NAME, | |
92 ER.FIELD_SPECIFIED_TWICE, ER.INVALID_GROUP_FUNC_USE, ER.UNSUPPORTED_EXTENSION, | |
93 ER.TABLE_MUST_HAVE_COLUMNS, ER.CANT_DO_THIS_DURING_AN_TRANSACTION) | |
94 _map_error(DataError, ER.WARN_DATA_TRUNCATED, ER.WARN_NULL_TO_NOTNULL, | |
95 ER.WARN_DATA_OUT_OF_RANGE, ER.NO_DEFAULT, ER.PRIMARY_CANT_HAVE_NULL, | |
96 ER.DATA_TOO_LONG, ER.DATETIME_FUNCTION_OVERFLOW) | |
97 _map_error(IntegrityError, ER.DUP_ENTRY, ER.NO_REFERENCED_ROW, | |
98 ER.NO_REFERENCED_ROW_2, ER.ROW_IS_REFERENCED, ER.ROW_IS_REFERENCED_2, | |
99 ER.CANNOT_ADD_FOREIGN) | |
100 _map_error(NotSupportedError, ER.WARNING_NOT_COMPLETE_ROLLBACK, ER.NOT_SUPPORTED_YET, | |
101 ER.FEATURE_DISABLED, ER.UNKNOWN_STORAGE_ENGINE) | |
102 | |
103 del Exception, StandardError, _map_error, ER |