#189 Exceptions not available on the connection

MySQLdb-1.2
closed
Andy Dustman
MySQLdb (285)
5
2012-09-19
2006-06-12
Paul Winkler
No

According to http://www.python.org/dev/peps/pep-0249/ ,
this is an optional DB API extension:

Connection Attributes .Error, .ProgrammingError, etc.

    All exception classes defined by the DB API

standard should be
exposed on the Connection objects as attributes
(in addition
to being available at module scope).

    These attributes simplify error handling in

multi-connection
environments.

This would be convenient for writing more portable code.
It would be nice if I could get exceptions from the
connection and not have to import them from whatever
db-api module I happen to be using.

Discussion

  • Andy Dustman
    Andy Dustman
    2006-06-13

    Logged In: YES
    user_id=71372

    Been there, done that.

    Python 2.4.2 (#1, Oct 14 2005, 01:36:01)
    [GCC 3.4.4 (Gentoo 3.4.4-r1, ssp-3.4.4-1.0, pie-8.7.8)] on
    linux2
    Type "help", "copyright", "credits" or "license" for more
    information.

    import MySQLdb
    db=MySQLdb.connect(db='test',read_default_file="~/.my.cnf")
    dir(db)
    ['DataError', 'DatabaseError', 'Error', 'IntegrityError',
    'InterfaceError', 'InternalError', 'NotSupportedError',
    'OperationalError', 'ProgrammingError', 'Warning',
    'class', 'delattr', 'dict', 'doc',
    'getattribute', 'hash', 'init', 'module',
    'new', 'reduce', 'reduce_ex', 'repr',
    'setattr', 'str', 'weakref', '_server_version',
    '_transactional', 'affected_rows', 'autocommit', 'begin',
    'change_user', 'character_set_name', 'client_flag', 'close',
    'commit', 'converter', 'cursor', 'cursorclass',
    'default_cursor', 'dump_debug_info', 'encoders', 'errno',
    'error', 'errorhandler', 'escape', 'escape_string',
    'field_count', 'get_character_set_info', 'get_host_info',
    'get_proto_info', 'get_server_info', 'info', 'insert_id',
    'kill', 'literal', 'messages', 'next_result', 'open',
    'ping', 'port', 'query', 'rollback', 'select_db',
    'server_capabilities', 'set_character_set',
    'set_server_option', 'set_sql_mode', 'show_warnings',
    'shutdown', 'sqlstate', 'stat', 'store_result',
    'string_decoder', 'string_literal', 'thread_id',
    'unicode_literal', 'use_result', 'warning_count']

     
  • Paul Winkler
    Paul Winkler
    2006-06-13

    Logged In: YES
    user_id=38329

    oops. sorry for the noise. Thanks!