Skip to content

Commit 3b4b2cf

Browse files
authored
bpo-43368: Fix fetching empty bytes in sqlite3 (GH-24706)
Regression introduced in 47feb1f.
1 parent 09605ad commit 3b4b2cf

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

Lib/sqlite3/test/regression.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,10 @@ def log(self, *args):
409409
self.con.execute("select 1") # trigger seg fault
410410
method(None)
411411

412+
def test_return_empty_bytestring(self):
413+
cur = self.con.execute("select X''")
414+
val = cur.fetchone()[0]
415+
self.assertEqual(val, b'')
412416

413417

414418
def suite():
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a regression introduced in GH-24562, where an empty bytestring was fetched
2+
as ``None`` instead of ``b''`` in :mod:`sqlite3`. Patch by Mariusz Felisiak.

Modules/_sqlite/cursor.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,8 @@ _pysqlite_fetch_one_row(pysqlite_Cursor* self)
333333
} else {
334334
/* coltype == SQLITE_BLOB */
335335
const char *blob = sqlite3_column_blob(self->statement->st, i);
336-
if (!blob) {
337-
converted = Py_NewRef(Py_None);
338-
} else {
339-
nbytes = sqlite3_column_bytes(self->statement->st, i);
340-
converted = PyBytes_FromStringAndSize(blob, nbytes);
341-
}
336+
nbytes = sqlite3_column_bytes(self->statement->st, i);
337+
converted = PyBytes_FromStringAndSize(blob, nbytes);
342338
}
343339
}
344340

0 commit comments

Comments
 (0)