From d8ae325dcbbfb9e442cbb2fd7b643ee6b8346edf Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Thu, 5 May 2011 10:06:41 -0700 Subject: [PATCH] stop being sloppy about close()ing SELECT cursors (#170) --- beets/library.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/beets/library.py b/beets/library.py index bc22a484f..9b48425bc 100644 --- a/beets/library.py +++ b/beets/library.py @@ -281,8 +281,9 @@ class Query(object): """ clause, subvals = self.clause() statement = 'SELECT COUNT(id), SUM(length) FROM items WHERE ' + clause - c = library.conn.cursor() - result = c.execute(statement, subvals).fetchone() + c = library.conn.execute(statement, subvals) + result = c.fetchone() + c.close() return (result[0], result[1] or 0.0) def execute(self, library): @@ -501,6 +502,12 @@ class ResultIterator(object): raise return Item(row) + def close(self): + self.cursor.close() + + def __del__(self): + self.close() + # An abstract library. @@ -981,10 +988,12 @@ class Library(BaseLibrary): if album_id is None: return None - record = self.conn.execute( + c = self.conn.execute( 'SELECT * FROM albums WHERE id=?', (album_id,) - ).fetchone() + ) + record = c.fetchone() + c.close() if record: return Album(self, dict(record))