mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
bpo-44859: Raise more accurate exceptions in sqlite3 (GH-27695)
* Improve exception compliance with PEP 249 * Raise InterfaceError instead of ProgrammingError for SQLITE_MISUSE. If SQLITE_MISUSE is raised, it is a sqlite3 module bug. Users of the sqlite3 module are not responsible for using the SQLite C API correctly. * Don't overwrite BufferError with ValueError when conversion to BLOB fails. * Raise ProgrammingError instead of Warning if user tries to execute() more than one SQL statement. * Raise ProgrammingError instead of ValueError if an SQL query contains null characters. * Make sure `_pysqlite_set_result` raises an exception if it returns -1.
This commit is contained in:
parent
96568e995d
commit
4674fd4e93
6 changed files with 45 additions and 14 deletions
|
|
@ -578,8 +578,6 @@ _pysqlite_set_result(sqlite3_context* context, PyObject* py_val)
|
|||
} else if (PyObject_CheckBuffer(py_val)) {
|
||||
Py_buffer view;
|
||||
if (PyObject_GetBuffer(py_val, &view, PyBUF_SIMPLE) != 0) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"could not convert BLOB to buffer");
|
||||
return -1;
|
||||
}
|
||||
if (view.len > INT_MAX) {
|
||||
|
|
@ -591,6 +589,11 @@ _pysqlite_set_result(sqlite3_context* context, PyObject* py_val)
|
|||
sqlite3_result_blob(context, view.buf, (int)view.len, SQLITE_TRANSIENT);
|
||||
PyBuffer_Release(&view);
|
||||
} else {
|
||||
callback_context *ctx = (callback_context *)sqlite3_user_data(context);
|
||||
PyErr_Format(ctx->state->ProgrammingError,
|
||||
"User-defined functions cannot return '%s' values to "
|
||||
"SQLite",
|
||||
Py_TYPE(py_val)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue