diff options
author | Erlend Egeberg Aasland <erlend.aasland@protonmail.com> | 2022-05-02 10:21:13 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-02 10:21:13 -0600 |
commit | 178d79ae67848e129958172e8a9ca4838f8503b9 (patch) | |
tree | 6099939212b3761ee757721438de034770bdc4e3 /Lib/sqlite3/test/hooks.py | |
parent | 67120224473f12e62a16a6985b9864b5cc3d0aa4 (diff) | |
download | cpython-git-178d79ae67848e129958172e8a9ca4838f8503b9.tar.gz |
[3.10] gh-89301: Fix regression with bound values in traced SQLite statements (#92147)
(cherry picked from commit 721aa96540bb96700f8c4bab0b4095b43491dca1)
Diffstat (limited to 'Lib/sqlite3/test/hooks.py')
-rw-r--r-- | Lib/sqlite3/test/hooks.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/sqlite3/test/hooks.py b/Lib/sqlite3/test/hooks.py index 8c60bdcf5d..97121eea1b 100644 --- a/Lib/sqlite3/test/hooks.py +++ b/Lib/sqlite3/test/hooks.py @@ -20,6 +20,7 @@ # misrepresented as being the original software. # 3. This notice may not be removed or altered from any source distribution. +import contextlib import unittest import sqlite3 as sqlite @@ -200,6 +201,16 @@ class ProgressTests(unittest.TestCase): self.assertEqual(action, 0, "progress handler was not cleared") class TraceCallbackTests(unittest.TestCase): + @contextlib.contextmanager + def check_stmt_trace(self, cx, expected): + try: + traced = [] + cx.set_trace_callback(lambda stmt: traced.append(stmt)) + yield + finally: + self.assertEqual(traced, expected) + cx.set_trace_callback(None) + def test_trace_callback_used(self): """ Test that the trace callback is invoked once it is set. @@ -261,6 +272,21 @@ class TraceCallbackTests(unittest.TestCase): cur.execute(queries[1]) self.assertEqual(traced_statements, queries) + def test_trace_expanded_sql(self): + expected = [ + "create table t(t)", + "BEGIN ", + "insert into t values(0)", + "insert into t values(1)", + "insert into t values(2)", + "COMMIT", + ] + cx = sqlite.connect(":memory:") + with self.check_stmt_trace(cx, expected): + with cx: + cx.execute("create table t(t)") + cx.executemany("insert into t values(?)", ((v,) for v in range(3))) + def suite(): tests = [ |