sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError?

Jon Clements joncle at googlemail.com
Tue Jun 16 19:09:36 CEST 2009


On Jun 16, 4:41 pm, Gabriel Rossetti <gabriel.rosse... at arimaz.com>
wrote:
> Hello everyone,
>
> I get an OperationalError with sqlite3 if I put the wrong column name,
> but shouldn't that be a ProgrammingError instead? I read PEP 249 and it
> says :
>
> "        OperationalError
>
>             Exception raised for errors that are related to the
>             database's operation and not necessarily under the control
>             of the programmer, e.g. an unexpected disconnect occurs,
>             the data source name is not found, a transaction could not
>             be processed, a memory allocation error occurred during
>             processing, etc.  It must be a subclass of DatabaseError.
>
>         ProgrammingError
>
>             Exception raised for programming errors, e.g. table not
>             found or already exists, syntax error in the SQL
>             statement, wrong number of parameters specified, etc.  It
>             must be a subclass of DatabaseError.
> "
>
> and to me it sounds more like a programming error than an operational
> error.
>
> Thank you,
> Gabriel

I would agree. With v2.5.2 of Python, I'm getting OperationalError
from sqlite3 and ProgrammingError from the psycopg2 (for postgres)
library. (Trying to create a table that already exists, trying to
'create tabel' and trying to select from non-existant tables)

I don't have time to go through code but looking at
http://www.sqlite.org/c3ref/c_abort.html, it would appear that there's
enough error results to distinguish between Operational and
Programming exceptions. Perhaps result != SQLITE_OK raises
OperationalError, or I'm looking at the wrong C spec for the version
in various Python versions etc... Or perhaps there's some chosen
rationale... or, perhaps, for an embedded engine, no one cares how it
failed, it just did...


Jon










More information about the Python-list mailing list