summaryrefslogtreecommitdiffstats
path: root/lib/bb/persist_data.py
diff options
context:
space:
mode:
authorChris Larson <chris_larson@mentor.com>2011-02-09 17:57:03 -0700
committerChris Larson <chris_larson@mentor.com>2011-04-05 17:21:48 -0700
commitd6fba8bad6277eb2a19e94f93a7a4baf74b29ef3 (patch)
treee41909a1981abb02246d821f416356f1b1781cc9 /lib/bb/persist_data.py
parent28958cd55e592853c68f5f2ba79381d1b8dcfb8f (diff)
downloadbitbake-contrib-d6fba8bad6277eb2a19e94f93a7a4baf74b29ef3.tar.gz
persist_data: make SQLTable a context manager
This can be used for more control over the underlying transactions. Unlike the context manager of, say, a file object, we can still use the object even after the end of a given with block, as the context manager exit only ensures we've committed to the database, not that we have closed the database. Signed-off-by: Chris Larson <chris_larson@mentor.com>
Diffstat (limited to 'lib/bb/persist_data.py')
-rw-r--r--lib/bb/persist_data.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/bb/persist_data.py b/lib/bb/persist_data.py
index aa2ede4b9..af96b76f4 100644
--- a/lib/bb/persist_data.py
+++ b/lib/bb/persist_data.py
@@ -55,6 +55,13 @@ class SQLTable(collections.MutableMapping):
def _execute(self, *query):
return self.cursor.execute(*query)
+ def __enter__(self):
+ self.cursor.__enter__()
+ return self
+
+ def __exit__(self, *excinfo):
+ self.cursor.__exit__(*excinfo)
+
def __getitem__(self, key):
data = self._execute("SELECT * from %s where key=?;" %
self.table, [key])