diff options
author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-03-03 14:16:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-03 14:16:24 (GMT) |
commit | 3b4b2cf418707c79f96689e401e3c703c0fdd4d2 (patch) | |
tree | 9b6feb5cc3c352f360c575ca90b986ab50d08ee0 | |
parent | 09605ad7269c8d9828fa3c175ad7c9efe8d12762 (diff) | |
download | cpython-3b4b2cf418707c79f96689e401e3c703c0fdd4d2.zip cpython-3b4b2cf418707c79f96689e401e3c703c0fdd4d2.tar.gz cpython-3b4b2cf418707c79f96689e401e3c703c0fdd4d2.tar.bz2 |
bpo-43368: Fix fetching empty bytes in sqlite3 (GH-24706)
Regression introduced in 47feb1feb28631b6647699b7633109aa85340966.
-rw-r--r-- | Lib/sqlite3/test/regression.py | 4 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2021-03-02-13-45-05.bpo-43368.t9XEkQ.rst | 2 | ||||
-rw-r--r-- | Modules/_sqlite/cursor.c | 8 |
3 files changed, 8 insertions, 6 deletions
diff --git a/Lib/sqlite3/test/regression.py b/Lib/sqlite3/test/regression.py index c8e0b27..417a531 100644 --- a/Lib/sqlite3/test/regression.py +++ b/Lib/sqlite3/test/regression.py @@ -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(): diff --git a/Misc/NEWS.d/next/Library/2021-03-02-13-45-05.bpo-43368.t9XEkQ.rst b/Misc/NEWS.d/next/Library/2021-03-02-13-45-05.bpo-43368.t9XEkQ.rst new file mode 100644 index 0000000..f9a4aa2 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-03-02-13-45-05.bpo-43368.t9XEkQ.rst @@ -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. diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index 23ab745..764eec5 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -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); } } |