-
Notifications
You must be signed in to change notification settings - Fork 562
Exceptions
Keith Erskine edited this page May 24, 2015
·
2 revisions
Python exceptions are raised by pyodbc when ODBC errors are detected. The exception classes specified in the Python DB API specification are used:
- DatabaseError
- DataError
- OperationalError
- IntegrityError
- InternalError
- ProgrammingError
- NotSupportedError
When an error occurs, the type of exception raised is based on the SQLSTATE value, typically provided by the database.
SQLSTATE | Exception |
---|---|
22xxx | pyodbc.DataError |
23xxx 40002 | pyodbc.IntegrityError |
24xxx 25xxx 42xxx | pyodbc.ProgrammingError |
0A000 | pyodbc.NotSupportedError |
All others | pyodbc.DatabaseError |
For example, a primary key error (attempting to insert a value when the key already exists) will raise an IntegrityError.