Skip to content

bpo-26187: Tests sqlite3 trace callback no duplicate on shcema changing #461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Lib/sqlite3/test/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import unittest
import sqlite3 as sqlite

from test.support import TESTFN, unlink

class CollationTests(unittest.TestCase):
def CheckCreateCollationNotString(self):
con = sqlite.connect(":memory:")
Expand Down Expand Up @@ -248,6 +250,24 @@ def trace(statement):
"Unicode data %s garbled in trace callback: %s"
% (ascii(unicode_value), ', '.join(map(ascii, traced_statements))))

@unittest.skipIf(sqlite.sqlite_version_info < (3, 3, 9), "sqlite3_prepare_v2 is not available")
def CheckTraceCallbackContent(self):
# set_trace_callback() shouldn't produce duplicate content (bpo-26187)
traced_statements = []
def trace(statement):
traced_statements.append(statement)

queries = ["create table foo(x)",
"insert into foo(x) values(1)"]
self.addCleanup(unlink, TESTFN)
con1 = sqlite.connect(TESTFN, isolation_level=None)
con2 = sqlite.connect(TESTFN)
con1.set_trace_callback(trace)
cur = con1.cursor()
cur.execute(queries[0])
con2.execute("create table bar(x)")
cur.execute(queries[1])
self.assertEqual(traced_statements, queries)


def suite():
Expand Down
4 changes: 4 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ Extension Modules
Library
-------

- bpo-26187: Test that sqlite3 trace callback is not called multiple
times when schema is changing. Indirectly fixed by switching to
use sqlite3_prepare_v2() in bpo-9303. Patch by Aviv Palivoda.

- bpo-29998: Pickling and copying ImportError now preserves name and path
attributes.

Expand Down