_mysql_exceptions.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. """_mysql_exceptions: Exception classes for _mysql and MySQLdb.
  2. These classes are dictated by the DB API v2.0:
  3. http://www.python.org/topics/database/DatabaseAPI-2.0.html
  4. """
  5. try:
  6. from exceptions import Exception, StandardError, Warning
  7. except ImportError:
  8. # Python 3
  9. StandardError = Exception
  10. class MySQLError(StandardError):
  11. """Exception related to operation with MySQL."""
  12. class Warning(Warning, MySQLError):
  13. """Exception raised for important warnings like data truncations
  14. while inserting, etc."""
  15. class Error(MySQLError):
  16. """Exception that is the base class of all other error exceptions
  17. (not Warning)."""
  18. class InterfaceError(Error):
  19. """Exception raised for errors that are related to the database
  20. interface rather than the database itself."""
  21. class DatabaseError(Error):
  22. """Exception raised for errors that are related to the
  23. database."""
  24. class DataError(DatabaseError):
  25. """Exception raised for errors that are due to problems with the
  26. processed data like division by zero, numeric value out of range,
  27. etc."""
  28. class OperationalError(DatabaseError):
  29. """Exception raised for errors that are related to the database's
  30. operation and not necessarily under the control of the programmer,
  31. e.g. an unexpected disconnect occurs, the data source name is not
  32. found, a transaction could not be processed, a memory allocation
  33. error occurred during processing, etc."""
  34. class IntegrityError(DatabaseError):
  35. """Exception raised when the relational integrity of the database
  36. is affected, e.g. a foreign key check fails, duplicate key,
  37. etc."""
  38. class InternalError(DatabaseError):
  39. """Exception raised when the database encounters an internal
  40. error, e.g. the cursor is not valid anymore, the transaction is
  41. out of sync, etc."""
  42. class ProgrammingError(DatabaseError):
  43. """Exception raised for programming errors, e.g. table not found
  44. or already exists, syntax error in the SQL statement, wrong number
  45. of parameters specified, etc."""
  46. class NotSupportedError(DatabaseError):
  47. """Exception raised in case a method or database API was used
  48. which is not supported by the database, e.g. requesting a
  49. .rollback() on a connection that does not support transaction or
  50. has transactions turned off."""