mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
bpo-43368: Fix fetching empty bytes in sqlite3 (GH-24706)
Regression introduced in 47feb1feb2
.
This commit is contained in:
parent
09605ad726
commit
3b4b2cf418
3 changed files with 8 additions and 6 deletions
|
@ -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():
|
||||
|
|
|
@ -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.
|
|
@ -333,14 +333,10 @@ _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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!converted) {
|
||||
goto error;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue