]> granicus.if.org Git - python/commitdiff
bpo-26187: Test that set_trace_callback() is not called multiple times (GH-461)
authorAviv Palivoda <palaviv@gmail.com>
Sun, 9 Apr 2017 09:11:59 +0000 (12:11 +0300)
committerBerker Peksag <berker.peksag@gmail.com>
Sun, 9 Apr 2017 09:11:59 +0000 (12:11 +0300)
conn.set_trace_callback() shouldn't be called multiple times when the
schema is changing.

This has indirectly been fixed by using sqlite3_prepare_v2() in bpo-9303.

Lib/sqlite3/test/hooks.py
Misc/NEWS

index f8ef4d88f3785508819a3333cb72eb33ec35928e..801a30cc34e88d90deff6d0cf7301bce19d5a850 100644 (file)
@@ -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:")
@@ -248,6 +250,24 @@ class TraceCallbackTests(unittest.TestCase):
                         "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():
index 910488af2c27a524a86bf2a5ff3f67d8002d91ad..cc0a4d759335a17c6f70147c03497c53659051d1 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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.