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: Improve some sqlite3 errors
Type: Stage: patch review
Components: Extension Modules Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: JelleZijlstra, berker.peksag, erlendaasland, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2021-08-07 14:14 by serhiy.storchaka, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 27654 merged serhiy.storchaka, 2021-08-07 14:33
PR 27695 merged erlendaasland, 2021-08-09 22:04
Messages (8)
msg399183 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-08-07 14:14
* MemoryError is now raised instead of sqlite3.Warning when memory is not enough for encoding statement to UTF-8 in Connection.__call__() and Cursor.execute().
* UnicodEncodeError is now raised instead of sqlite3.Warning when statement contains surrogate characters in Connection.__call__() and Cursor.execute().
* TypeError is now raised instead of ValueError for non-string script in Cursor.execute().
* ValueError is now raised for script containing NUL instead of truncating it in Cursor.execute().
* Correctly handled exceptions raised when getting boolean value of the result of the progress handler to bool.

Also added many tests which cover different exceptional cases.
msg399185 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-08-07 14:23
There is also a problem with the sqlite3.InterfaceError raised when bind parameters with message "Error binding parameter XXX - probably unsupported type." It is raised not only for unsupported types, but:

* For too large integers (outside of the range of signed 64-bit integers).
* For too large strings and blobs with size <= INT_MAX but larger than the SQLite limit (1_000_000_000 by default). But OverflowError is raised for size >= INT_MAX.
* When memory error or any other error occurred inside SQLite.
msg399187 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-08-07 14:34
Entries 3 and 4 are about Cursor.executescript(), not Cursor.execute().
msg399211 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-08-08 05:50
New changeset 0eec6276fdcdde5221370d92b50ea95851760c72 by Serhiy Storchaka in branch 'main':
bpo-44859: Improve error handling in sqlite3 and and raise more accurate exceptions. (GH-27654)
https://github.com/python/cpython/commit/0eec6276fdcdde5221370d92b50ea95851760c72
msg399241 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-08-08 20:52
* sqlite3.ProgrammingError is raised for SQLITE_MISUSE. IMO, sqlite3.InterfaceError, is more appropriate.
* In case of too large integer values, OverflowError is raised on bind, but sqlite3.DataError is raised on UDF return. Using sqlite3.DataError in both cases would be more aligned with PEP 249.
* Too long strings/blobs raise OverflowError. Consider raising sqlite3.DataError instead.
* For non-contiguous (blob) buffers, we overwrite the BufferError with ValueError. Instead of overwriting BufferError, we should consider chaining with sqlite3.DataError.
* Consider raising sqlite3.Warning when nan is implicitly converted to NULL by SQLite
* In pysqlite_statement_create(), consider raising sqlite3.ProgrammingError iso. sqlite3.Warning when more than one statement is executed
* In pysqlite_statement_create(), consider raising sqlite3.DataError iso. ValueError for queries with null characters
msg399289 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-08-09 20:57
Also, for SQLite 3.7.17 and above, we should raise sqlite3.Warning for error codes SQLITE_NOTICE and SQLITE_WARNING.
msg399441 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-08-12 11:10
> Also, for SQLite 3.7.17 and above, we should raise sqlite3.Warning for error codes SQLITE_NOTICE and SQLITE_WARNING.

Er, forget that. Neither are returned by any SQLite C interface, at the moment. They can (currently) only be used as the first argument to sqlite3_log().
msg415388 - (view) Author: Jelle Zijlstra (JelleZijlstra) * (Python committer) Date: 2022-03-17 05:58
New changeset 4674fd4e938eb4a29ccd5b12c15455bd2a41c335 by Erlend Egeberg Aasland in branch 'main':
bpo-44859: Raise more accurate exceptions in `sqlite3` (GH-27695)
https://github.com/python/cpython/commit/4674fd4e938eb4a29ccd5b12c15455bd2a41c335
History
Date User Action Args
2022-04-11 14:59:48adminsetgithub: 89022
2022-03-17 05:58:28JelleZijlstrasetnosy: + JelleZijlstra
messages: + msg415388
2021-08-12 11:10:42erlendaaslandsetmessages: + msg399441
2021-08-09 22:04:06erlendaaslandsetpull_requests: + pull_request26181
2021-08-09 20:57:37erlendaaslandsetmessages: + msg399289
2021-08-08 20:52:03erlendaaslandsetmessages: + msg399241
2021-08-08 05:50:00serhiy.storchakasetmessages: + msg399211
2021-08-07 14:34:44serhiy.storchakasetmessages: + msg399187
2021-08-07 14:33:09serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request26148
2021-08-07 14:23:44serhiy.storchakasetmessages: + msg399185
2021-08-07 14:14:16serhiy.storchakacreate