From 2faa434d9a67a7578ddc9db5e206c3d37f6a8e9f Mon Sep 17 00:00:00 2001 From: palaviv Date: Sat, 4 Mar 2017 11:29:31 +0200 Subject: [PATCH 1/5] Test that no duplicate line is traced when schema is changing --- Lib/sqlite3/test/hooks.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Lib/sqlite3/test/hooks.py b/Lib/sqlite3/test/hooks.py index f8ef4d88f37855..901a989a94a25d 100644 --- a/Lib/sqlite3/test/hooks.py +++ b/Lib/sqlite3/test/hooks.py @@ -23,6 +23,7 @@ import unittest import sqlite3 as sqlite +from tempfile import NamedTemporaryFile class CollationTests(unittest.TestCase): def CheckCreateCollationNotString(self): @@ -248,6 +249,27 @@ 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): + """ + Test that the statement are correct. Fix for bpo-26187 + """ + with NamedTemporaryFile(suffix='.sqlite') as db_path: + traced_statements = [] + def trace(statement): + traced_statements.append(statement) + + queries = ["create table foo(x)", + "insert into foo(x) values(1)"] + con1 = sqlite.connect(db_path.name, isolation_level=None) + con2 = sqlite.connect(db_path.name) + 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(): From 97e3b881749c185271bf6b3088c30e12d52ec707 Mon Sep 17 00:00:00 2001 From: palaviv Date: Sun, 12 Mar 2017 19:19:12 +0200 Subject: [PATCH 2/5] Add NEWS entry --- Misc/NEWS | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Misc/NEWS b/Misc/NEWS index 899723937c84a1..86d3d2c946cffb 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -259,6 +259,10 @@ Extension Modules Library ------- +- bpo-26187: Test that sqlite trace callback is not called multiple + times when schema is changing. Fixed by bpo-9303 + (Migrate sqlite3 module to _v2 API). Patch by Aviv Palivoda. + - bpo-29623: Allow use of path-like object as a single argument in ConfigParser.read(). Patch by David Ellis. From 94dd92de9479480f900a4db92764f2b419651a71 Mon Sep 17 00:00:00 2001 From: palaviv Date: Sun, 12 Mar 2017 19:35:30 +0200 Subject: [PATCH 3/5] CR fixes --- Lib/sqlite3/test/hooks.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Lib/sqlite3/test/hooks.py b/Lib/sqlite3/test/hooks.py index 901a989a94a25d..077821ede98037 100644 --- a/Lib/sqlite3/test/hooks.py +++ b/Lib/sqlite3/test/hooks.py @@ -23,7 +23,7 @@ import unittest import sqlite3 as sqlite -from tempfile import NamedTemporaryFile +import tempfile class CollationTests(unittest.TestCase): def CheckCreateCollationNotString(self): @@ -252,15 +252,15 @@ def trace(statement): @unittest.skipIf(sqlite.sqlite_version_info < (3, 3, 9), "sqlite3_prepare_v2 is not available") def CheckTraceCallbackContent(self): """ - Test that the statement are correct. Fix for bpo-26187 + bpo-26187 """ - with NamedTemporaryFile(suffix='.sqlite') as db_path: - traced_statements = [] - def trace(statement): - traced_statements.append(statement) + traced_statements = [] + def trace(statement): + traced_statements.append(statement) - queries = ["create table foo(x)", - "insert into foo(x) values(1)"] + queries = ["create table foo(x)", + "insert into foo(x) values(1)"] + with tempfile.NamedTemporaryFile(suffix='.sqlite') as db_path: con1 = sqlite.connect(db_path.name, isolation_level=None) con2 = sqlite.connect(db_path.name) con1.set_trace_callback(trace) @@ -271,7 +271,6 @@ def trace(statement): self.assertEqual(traced_statements, queries) - def suite(): collation_suite = unittest.makeSuite(CollationTests, "Check") progress_suite = unittest.makeSuite(ProgressTests, "Check") From 7f117385549748bb382001ca52f982e8a69b7a21 Mon Sep 17 00:00:00 2001 From: palaviv Date: Sun, 12 Mar 2017 22:10:44 +0200 Subject: [PATCH 4/5] Use TESTSFN instead of NamedTemporaryFile --- Lib/sqlite3/test/hooks.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Lib/sqlite3/test/hooks.py b/Lib/sqlite3/test/hooks.py index 077821ede98037..d2fbc2fa492414 100644 --- a/Lib/sqlite3/test/hooks.py +++ b/Lib/sqlite3/test/hooks.py @@ -23,7 +23,8 @@ import unittest import sqlite3 as sqlite -import tempfile + +from test.support import TESTFN, unlink class CollationTests(unittest.TestCase): def CheckCreateCollationNotString(self): @@ -260,15 +261,15 @@ def trace(statement): queries = ["create table foo(x)", "insert into foo(x) values(1)"] - with tempfile.NamedTemporaryFile(suffix='.sqlite') as db_path: - con1 = sqlite.connect(db_path.name, isolation_level=None) - con2 = sqlite.connect(db_path.name) - 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) + 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(): From 3c21e8b1f00a73b85d75461e18e47900af43fa64 Mon Sep 17 00:00:00 2001 From: palaviv Date: Thu, 23 Mar 2017 20:32:26 +0200 Subject: [PATCH 5/5] CR fixes --- Lib/sqlite3/test/hooks.py | 4 +--- Misc/NEWS | 7 +++---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Lib/sqlite3/test/hooks.py b/Lib/sqlite3/test/hooks.py index d2fbc2fa492414..801a30cc34e88d 100644 --- a/Lib/sqlite3/test/hooks.py +++ b/Lib/sqlite3/test/hooks.py @@ -252,9 +252,7 @@ def trace(statement): @unittest.skipIf(sqlite.sqlite_version_info < (3, 3, 9), "sqlite3_prepare_v2 is not available") def CheckTraceCallbackContent(self): - """ - bpo-26187 - """ + # set_trace_callback() shouldn't produce duplicate content (bpo-26187) traced_statements = [] def trace(statement): traced_statements.append(statement) diff --git a/Misc/NEWS b/Misc/NEWS index 4452c02a38f049..66a927472d9ae0 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -278,9 +278,9 @@ Extension Modules Library ------- -- bpo-26187: Test that sqlite trace callback is not called multiple - times when schema is changing. Fixed by bpo-9303 - (Migrate sqlite3 module to _v2 API). Patch by Aviv Palivoda. +- 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-8256: Fixed possible failing or crashing input() if attributes "encoding" or "errors" of sys.stdin or sys.stdout are not set or are not strings. @@ -306,7 +306,6 @@ Library check identity before checking equality when do comparisons. - bpo-28682: Added support for bytes paths in os.fwalk(). ->>>>>>> upstream/master - bpo-29623: Allow use of path-like object as a single argument in ConfigParser.read(). Patch by David Ellis.