This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: sqlite3: some OperationalError exceptions should be ProgrammingError (PEP 249)
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.6
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: ghaering Nosy List: dontbugme, ghaering, gruszczy
Priority: normal Keywords: patch

Created on 2009-11-25 16:39 by dontbugme, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
sqlite_ProgrammingError.patch gruszczy, 2009-11-30 13:40
Messages (3)
msg95719 - (view) Author: (dontbugme) Date: 2009-11-25 16:39
The following code raises OperationalError exceptions:
python -c 'import sqlite3; sqlite3.connect(":memory:").execute("bad
syntax")'
python -c 'import sqlite3; sqlite3.connect(":memory:").execute("SELECT *
FROM no_such_table")'
python -c 'import sqlite3; sqlite3.connect(":memory:").execute("SELECT
no_such_column")'

But ProgrammingError should be raised, as per PEP 249:

        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.
msg95837 - (view) Author: Filip Gruszczyński (gruszczy) Date: 2009-11-30 13:40
I have created some naive patch, that makes sqlite module raise
ProgrammingError for SQLITE_ERROR code. But I don't know, whether it
might raise ProgrammingError in situation, when OperationalError should be.

Sqlite docs says: 

#define SQLITE_ERROR        1   /* SQL error or missing database */

and I don't really know, whether missing database is operational error
or a programming one. Seems like the first one, but this would error
message string parsing, that doesn't seem to pretty. Could anyone
suggest me, what else could be done?
msg96562 - (view) Author: Gerhard Häring (ghaering) * (Python committer) Date: 2009-12-18 13:54
The error code SQLITE_ERROR from SQLite is used for "runtime errors".
These can either be caused by the programmer (table does not exist, SQL
contains errors) or they can be other problems like constraint
violations etc.

To differentiate these we would need to parse the error message returned
by sqlite3_errmsg(). This is a path I don't want to go: it's hard to get
this right across current and future SQLite versions.

So I'm closing this issue as wontfix.
History
Date User Action Args
2022-04-11 14:56:55adminsetgithub: 51643
2009-12-18 13:54:37ghaeringsetstatus: open -> closed
assignee: ghaering
resolution: wont fix
messages: + msg96562
2009-12-11 13:11:27pitrousetnosy: + ghaering
2009-11-30 13:40:42gruszczysetfiles: + sqlite_ProgrammingError.patch

nosy: + gruszczy
messages: + msg95837

keywords: + patch
2009-11-25 16:39:18dontbugmecreate