bpo-43368: Fix fetching empty bytes in sqlite3 (GH-24706)

Regression introduced in 47feb1feb2.
This commit is contained in:
Mariusz Felisiak 2021-03-03 15:16:24 +01:00 committed by GitHub
parent 09605ad726
commit 3b4b2cf418
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 6 deletions

View File

@ -409,6 +409,10 @@ class RegressionTests(unittest.TestCase):
self.con.execute("select 1") # trigger seg fault
method(None)
def test_return_empty_bytestring(self):
cur = self.con.execute("select X''")
val = cur.fetchone()[0]
self.assertEqual(val, b'')
def suite():

View File

@ -0,0 +1,2 @@
Fix a regression introduced in GH-24562, where an empty bytestring was fetched
as ``None`` instead of ``b''`` in :mod:`sqlite3`. Patch by Mariusz Felisiak.

View File

@ -333,12 +333,8 @@ _pysqlite_fetch_one_row(pysqlite_Cursor* self)
} else {
/* coltype == SQLITE_BLOB */
const char *blob = sqlite3_column_blob(self->statement->st, i);
if (!blob) {
converted = Py_NewRef(Py_None);
} else {
nbytes = sqlite3_column_bytes(self->statement->st, i);
converted = PyBytes_FromStringAndSize(blob, nbytes);
}
nbytes = sqlite3_column_bytes(self->statement->st, i);
converted = PyBytes_FromStringAndSize(blob, nbytes);
}
}