Revision 1904
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql.py | ||
---|---|---|
129 | 129 |
|
130 | 130 |
def execute(self, query, params=None): |
131 | 131 |
self.query_lookup = _query_lookup(query, params) |
132 |
return_value = self.inner.execute(query, params) |
|
133 |
self.query = get_cur_query(self.inner) |
|
132 |
try: return_value = self.inner.execute(query, params) |
|
133 |
except Exception, e: |
|
134 |
self.result = e # cache the exception as the result |
|
135 |
self._cache_result() |
|
136 |
raise |
|
137 |
finally: self.query = get_cur_query(self.inner) |
|
134 | 138 |
return return_value |
135 | 139 |
|
136 | 140 |
def fetchone(self): |
137 | 141 |
row = self.inner.fetchone() |
138 | 142 |
if row != None: self.result.append(row) |
139 | 143 |
# otherwise, fetched all rows |
140 |
elif self.query_results != None: # is caching |
|
144 |
else: self._cache_result() |
|
145 |
return row |
|
146 |
|
|
147 |
def _cache_result(self): |
|
148 |
if self.query_results != None: # is caching |
|
141 | 149 |
assert self.query_lookup != None |
142 | 150 |
self.query_results[self.query_lookup] = (self.query, |
143 | 151 |
self.result) |
144 |
return row |
|
145 | 152 |
|
146 | 153 |
class CacheCursor: |
147 | 154 |
def __init__(self, query, result): |
148 | 155 |
self.query = query |
156 |
if isinstance(result, Exception): raise result |
|
157 |
# otherwise, result is a rows list |
|
149 | 158 |
self.rowcount = len(result) |
150 | 159 |
self.iter = iter(result) |
151 | 160 |
|
Also available in: Unified diff
sql.py: DbConn.run_query(): Cache exceptions raised by queries as well