]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-69093: improve sqlite3.Connection.blobopen() error handling (GH-91571)
authorErlend Egeberg Aasland <erlend.aasland@innova.no>
Fri, 15 Apr 2022 16:27:39 +0000 (18:27 +0200)
committerGitHub <noreply@github.com>
Fri, 15 Apr 2022 16:27:39 +0000 (09:27 -0700)
Unless sqlite3_blob_open() returns SQLITE_MISUSE, the error code and
message are available on the connection object. This means we have to
handle SQLITE_MISUSE error messages explicitly.

Modules/_sqlite/connection.c

index 85fb128fc7f1c0d9101f29dca57f04ed8e6988a1..0028cf72f997a9310bf9d74671cd8cce99779e2f 100644 (file)
@@ -475,7 +475,11 @@ blobopen_impl(pysqlite_Connection *self, const char *table, const char *col,
     rc = sqlite3_blob_open(self->db, name, table, col, row, !readonly, &blob);
     Py_END_ALLOW_THREADS
 
-    if (rc != SQLITE_OK) {
+    if (rc == SQLITE_MISUSE) {
+        PyErr_Format(self->state->InterfaceError, sqlite3_errstr(rc));
+        return NULL;
+    }
+    else if (rc != SQLITE_OK) {
         _pysqlite_seterror(self->state, self->db);
         return NULL;
     }