Skip to content

Commit 32fcc41

Browse files
author
Erlend E. Aasland
committed
Simplify
https://sqlite.org/c3ref/value_blob.html: "As long as the input parameter is correct, these routines can only fail if an out-of-memory error occurs during a format conversion."
1 parent edf5a5a commit 32fcc41

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

Modules/_sqlite/connection.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -571,22 +571,16 @@ _pysqlite_build_py_params(sqlite3_context *context, int argc,
571571
}
572572
break;
573573
case SQLITE_BLOB: {
574+
sqlite3 *db = sqlite3_context_db_handle(context);
574575
const void *blob = sqlite3_value_blob(cur_value);
575576

576-
if (blob) {
577-
Py_ssize_t size = sqlite3_value_bytes(cur_value);
578-
cur_py_value = PyBytes_FromStringAndSize(blob, size);
579-
}
580-
else {
581-
sqlite3 *db = sqlite3_context_db_handle(context);
582-
assert(db != NULL);
583-
if (sqlite3_errcode(db) == SQLITE_NOMEM) {
584-
PyErr_NoMemory();
585-
goto error;
586-
}
587-
// Zero-sized blob.
588-
cur_py_value = PyBytes_FromStringAndSize(NULL, 0);
577+
if (blob == NULL && sqlite3_errcode(db) == SQLITE_NOMEM) {
578+
PyErr_NoMemory();
579+
goto error;
589580
}
581+
582+
Py_ssize_t size = sqlite3_value_bytes(cur_value);
583+
cur_py_value = PyBytes_FromStringAndSize(blob, size);
590584
break;
591585
}
592586
case SQLITE_NULL:

0 commit comments

Comments
 (0)