[issue44041] [sqlite3] optimisation: only call sqlite3_column_count when needed
Erlend E. Aasland
report at bugs.python.org
Fri Jun 4 08:07:59 EDT 2021
Erlend E. Aasland <erlend.aasland at innova.no> added the comment:
This change breaks existing behaviour (see test below). Also, sqlite3_column_count() is implemented as a simple lookup in SQLite; it is never an expensive function. Suggests to add the following test instead:
diff --git a/Lib/sqlite3/test/dbapi.py b/Lib/sqlite3/test/dbapi.py
index 77fafe0930..d7a3b249ab 100644
--- a/Lib/sqlite3/test/dbapi.py
+++ b/Lib/sqlite3/test/dbapi.py
@@ -555,6 +555,17 @@ def test_last_row_id_insert_o_r(self):
]
self.assertEqual(results, expected)
+ def test_column_count(self):
+ # Check that column count is updated correctly for cached statements
+ select = "select * from test"
+ res = self.cu.execute(select)
+ old_count = len(res.description)
+ # Add a new column and execute the cached select query again
+ self.cu.execute("alter table test add newcol")
+ res = self.cu.execute(select)
+ new_count = len(res.description)
+ self.assertEqual(old_count - new_count, 1)
+
class ThreadTests(unittest.TestCase):
def setUp(self):
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44041>
_______________________________________
More information about the Python-bugs-list
mailing list