mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
[3.10] gh-89301: Fix regression with bound values in traced SQLite statements (#92147)
(cherry picked from commit 721aa96540
)
This commit is contained in:
parent
6712022447
commit
178d79ae67
3 changed files with 79 additions and 17 deletions
|
@ -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 = [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue