Revision 1903
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql.py | ||
---|---|---|
155 | 155 |
|
156 | 156 |
def run_query(self, query, params=None, cacheable=False): |
157 | 157 |
query_lookup = _query_lookup(query, params) |
158 |
try: actual_query, result = self.query_results[query_lookup] |
|
159 |
except KeyError: |
|
160 |
cur = self.DbCursor(self, cacheable) |
|
161 |
try: cur.execute(query, params) |
|
162 |
except Exception, e: |
|
163 |
_add_cursor_info(e, cur) |
|
164 |
raise |
|
165 |
finally: |
|
166 |
if self.log_debug != log_debug_none:# only compute msg if needed |
|
167 |
self.log_debug(strings.one_line(get_cur_query(cur))) |
|
168 |
return cur |
|
169 |
else: return self.CacheCursor(actual_query, result) |
|
158 |
used_cache = False |
|
159 |
try: |
|
160 |
try: |
|
161 |
if not cacheable: raise KeyError |
|
162 |
actual_query, result = self.query_results[query_lookup] |
|
163 |
used_cache = True |
|
164 |
except KeyError: |
|
165 |
cur = self.DbCursor(self, cacheable) |
|
166 |
try: cur.execute(query, params) |
|
167 |
except Exception, e: |
|
168 |
_add_cursor_info(e, cur) |
|
169 |
raise |
|
170 |
else: cur = self.CacheCursor(actual_query, result) |
|
171 |
finally: |
|
172 |
if self.log_debug != log_debug_none: # only compute msg if needed |
|
173 |
if used_cache: cache_status = 'Cache hit' |
|
174 |
elif cacheable: cache_status = 'Cache miss' |
|
175 |
else: cache_status = 'Non-cacheable' |
|
176 |
self.log_debug(cache_status+': '+strings.one_line(cur.query)) |
|
177 |
|
|
178 |
return cur |
|
170 | 179 |
|
171 | 180 |
connect = DbConn |
172 | 181 |
|
Also available in: Unified diff
sql.py: DbConn.run_query(): When debug logging, label queries with their cache status (hit/miss/non-cacheable)