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:
Erlend Egeberg Aasland 2022-03-17 06:58:25 +01:00 committed by GitHub
parent 96568e995d
commit 4674fd4e93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 14 deletions

View file

@ -67,7 +67,7 @@ pysqlite_statement_create(pysqlite_Connection *connection, PyObject *sql)
return NULL;
}
if (strlen(sql_cstr) != (size_t)size) {
PyErr_SetString(PyExc_ValueError,
PyErr_SetString(connection->ProgrammingError,
"the query contains a null character");
return NULL;
}
@ -85,7 +85,7 @@ pysqlite_statement_create(pysqlite_Connection *connection, PyObject *sql)
}
if (pysqlite_check_remaining_sql(tail)) {
PyErr_SetString(connection->Warning,
PyErr_SetString(connection->ProgrammingError,
"You can only execute one statement at a time.");
goto error;
}
@ -190,7 +190,6 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
case TYPE_BUFFER: {
Py_buffer view;
if (PyObject_GetBuffer(parameter, &view, PyBUF_SIMPLE) != 0) {
PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer");
return -1;
}
if (view.len > INT_MAX) {