This is an automated email from the ASF dual-hosted git repository. gstein pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/steve.git
commit 36a0671399f9b89180e19c68c98c17d09290e3c2 Author: Greg Stein <[email protected]> AuthorDate: Mon May 30 19:21:25 2022 -0500 ensure cursors complete, to release locks --- v3/steve/db.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/v3/steve/db.py b/v3/steve/db.py index 884dc93..3df4359 100644 --- a/v3/steve/db.py +++ b/v3/steve/db.py @@ -46,9 +46,6 @@ class DB: self.conn = sqlite3.connect(fname, isolation_level=None) self.conn.row_factory = row_factory - # For fetching column names. - self.name_cursor = self.conn.cursor() - # CURSOR : FACTORY self.factories = { } @@ -63,9 +60,13 @@ class DB: assert query[:9].lower() == 'select * ' # Get all column names for TABLE. - self.name_cursor.execute(f'select * from {table} limit 1') - names = [ info[0] for info in self.name_cursor.description ] - self.name_cursor.close() # we don't need the results + cur = self.conn.execute(f'select * from {table} limit 1') + names = [ info[0] for info in cur.description ] + + # We don't need the results, but cannot leave the cursor hanging, + # as it establishes a lock on this table. This likely closes as + # this method exits, but let's not rely upon that. + cur.close() # Create a factory for turning rows into namedtuples. factory = collections.namedtuple(f'row_factory_{len(self.factories)}', @@ -102,4 +103,6 @@ class NamedTupleCursor(sqlite3.Cursor): def first_row(self, params=()): "Helper method to fetch the first row of a query." self.perform(params) - return self.fetchone() + row = self.fetchone() + _ = self.fetchall() # run the cursor to completion; should be empty + return row
