8000 bpo-44859: Raise more accurate exceptions in `sqlite3` by erlend-aasland · Pull Request #27695 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-44859: Raise more accurate exceptions in sqlite3 #27695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address reviews
  • Loading branch information
Erlend E. Aasland committed Mar 8, 2022
commit 3792cf0deb82d3aee60d9e2d691cf8539fd37e62
5 changes: 2 additions & 3 deletions Lib/test/test_sqlite3/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,12 @@ def test_null_character(self):
# Issue #21147
cur = self.con.cursor()
queries = ["\0select 1", "select 1\0"]
msg = "the query contains a null character"
for query in queries:
with self.subTest(query=query):
self.assertRaisesRegex(sqlite.DataError, msg,
self.assertRaisesRegex(sqlite.ProgrammingError, "null char",
self.con.execute, query)
with self.subTest(query=query):
self.assertRaisesRegex(sqlite.DataError, msg,
self.assertRaisesRegex(sqlite.ProgrammingError, "null char",
cur.execute, query)

def test_surrogates(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
Raise more accurate exceptions in :mod:`sqlite3`.
Raise more accurate and :pep:`249` compatible exceptions in :mod:`sqlite3`.

* Raise InterfaceError iso. ProgrammingError for SQLITE_MISUSE
* Don't overwrite BufferError with ValueError when converting to BLOB
* Raise ProgrammingError iso. Warning if user tries to execute() more than one
statement
* Raise DataError iso. ValueError if query contains NULL characters
* Raise :exc:`~sqlite3.InterfaceError` instead of
:exc:`~sqlite3.ProgrammingError` for ``SQLITE_MISUSE`` errors.
* Don't overwrite :exc:`BufferError` with :exc:`ValueError` when conversion to
BLOB fails.
* Raise :exc:`~sqlite3.ProgrammingError` instead of :exc:`~sqlite3.Warning` if
user tries to :meth:`~sqlite3.Cursor.execute()` more than one SQL statement.
* Raise :exc:`~sqlite3.ProgrammingError` instead of :exc:`ValueError` if an SQL
query contains null characters.
3 changes: 2 additions & 1 deletion Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,8 @@ _pysqlite_set_result(sqlite3_context* context, PyObject* py_val)
} else {
callback_context *ctx = (callback_context *)sqlite3_user_data(context);
PyErr_Format(ctx->state->ProgrammingError,
"UDF's cannot return '%s' values to SQLite",
"User-defined functions cannot return '%s' values to "
"SQLite",
Py_TYPE(py_val)->tp_name);
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/_sqlite/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pysqlite_statement_create(pysqlite_Connection *connection, PyObject *sql)
return NULL;
}
if (strlen(sql_cstr) != (size_t)size) {
PyErr_SetString(connection->DataError,
PyErr_SetString(connection->ProgrammingError,
"the query contains a null character");
return NULL;
}
Expand Down
0