From 5a97877e14409764aa6464fbda9741f21607fa2b Mon Sep 17 00:00:00 2001 From: Charles Leifer Date: Sun, 25 Jun 2023 20:48:42 -0500 Subject: [PATCH] Exclude pragma from is_dml logic and implicit transaction. --- src/statement.c | 3 ++- test/transactions.py | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/statement.c b/src/statement.c index fb1b8bd..cea3596 100644 --- a/src/statement.c +++ b/src/statement.c @@ -104,7 +104,8 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con PyOS_strnicmp(p, "alter", 5) && PyOS_strnicmp(p, "analyze", 7) && PyOS_strnicmp(p, "reindex", 7) && - PyOS_strnicmp(p, "vacuum", 6)); + PyOS_strnicmp(p, "vacuum", 6) && + PyOS_strnicmp(p, "pragma", 6)); break; } } diff --git a/test/transactions.py b/test/transactions.py index 1421961..46105fe 100644 --- a/test/transactions.py +++ b/test/transactions.py @@ -21,7 +21,7 @@ # misrepresented as being the original software. # 3. This notice may not be removed or altered from any source distribution. -import os, unittest +import glob, os, unittest from sqlcipher3 import dbapi2 as sqlite def get_db_path(): @@ -212,6 +212,14 @@ class DMLStatementDetectionTestCase(unittest.TestCase): Use sqlite3_stmt_readonly to determine if the statement is DML or not. """ + def setUp(self): + for f in glob.glob(get_db_path() + '*'): + try: + os.unlink(f) + except OSError: + pass + tearDown = setUp + @unittest.skipIf(sqlite.sqlite_version_info < (3, 8, 3), 'needs sqlite 3.8.3 or newer') def test_dml_detection_cte(self): @@ -268,6 +276,13 @@ def test_dml_detection_vacuum(self): conn.execute('vacuum') self.assertFalse(conn.in_transaction) + def test_dml_detection_vacuum(self): + conn = sqlite.connect(get_db_path()) + conn.execute('pragma journal_mode=\'wal\'') + jmode, = conn.execute('pragma journal_mode').fetchone() + self.assertEqual(jmode, 'wal') + self.assertFalse(conn.in_transaction) + def suite(): default_suite = unittest.makeSuite(TransactionTests, "Check")