]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45041: Restore `sqlite3` executescript behaviour for `SELECT` queries (GH-28509)
authorErlend Egeberg Aasland <erlend.aasland@innova.no>
Thu, 7 Oct 2021 09:16:45 +0000 (11:16 +0200)
committerGitHub <noreply@github.com>
Thu, 7 Oct 2021 09:16:45 +0000 (10:16 +0100)
* bpo-45041: Restore sqlite3 executescript behaviour for select queries

* Add regression test

Lib/sqlite3/test/test_regression.py
Modules/_sqlite/cursor.c

index ff356734860b645c504b4a3e9023ba9320800bf2..3d71809d9c11cf87f32911f127fa5b54cb12c2e7 100644 (file)
@@ -475,6 +475,17 @@ class RegressionTests(unittest.TestCase):
             con.execute("drop table t")
             con.commit()
 
+    def test_executescript_step_through_select(self):
+        with managed_connect(":memory:", in_mem=True) as con:
+            values = [(v,) for v in range(5)]
+            with con:
+                con.execute("create table t(t)")
+                con.executemany("insert into t values(?)", values)
+            steps = []
+            con.create_function("step", 1, lambda x: steps.append((x,)))
+            con.executescript("select step(t) from t")
+            self.assertEqual(steps, values)
+
 
 if __name__ == "__main__":
     unittest.main()
index 38ccdcf5379d05ff292f8c1fc4e3627b2cc3a261..ca74a68de4dba79e89c1b80cb48b9324f52be5fd 100644 (file)
@@ -760,7 +760,7 @@ pysqlite_cursor_executescript_impl(pysqlite_Cursor *self,
                                 &tail);
         if (rc == SQLITE_OK) {
             do {
-                (void)sqlite3_step(stmt);
+                rc = sqlite3_step(stmt);
             } while (rc == SQLITE_ROW);
             rc = sqlite3_finalize(stmt);
         }