Revision 2170
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql.py | ||
---|---|---|
16 | 16 |
|
17 | 17 |
##### Exceptions |
18 | 18 |
|
19 |
def get_cur_query(cur, input_query=None): |
|
19 |
def get_cur_query(cur, input_query=None, input_params=None):
|
|
20 | 20 |
raw_query = None |
21 | 21 |
if hasattr(cur, 'query'): raw_query = cur.query |
22 | 22 |
elif hasattr(cur, '_last_executed'): raw_query = cur._last_executed |
23 |
return util.coalesce(raw_query, input_query) |
|
23 |
|
|
24 |
if raw_query != None: return raw_query |
|
25 |
else: return repr(input_query)+' % '+repr(input_params) |
|
24 | 26 |
|
25 |
def _add_cursor_info(e, cur, input_query=None): |
|
26 |
exc.add_msg(e, 'query: '+str(get_cur_query(cur, input_query))) |
|
27 |
def _add_cursor_info(e, *args, **kw_args): |
|
28 |
'''For params, see get_cur_query()''' |
|
29 |
exc.add_msg(e, 'query: '+str(get_cur_query(*args, **kw_args))) |
|
27 | 30 |
|
28 | 31 |
class DbException(exc.ExceptionWithCause): |
29 | 32 |
def __init__(self, msg, cause=None, cur=None): |
... | ... | |
201 | 204 |
try: return_value = self.inner.execute(query, params) |
202 | 205 |
finally: self.query = get_cur_query(self.inner) |
203 | 206 |
except Exception, e: |
204 |
_add_cursor_info(e, self, query) |
|
207 |
_add_cursor_info(e, self, query, params)
|
|
205 | 208 |
self.result = e # cache the exception as the result |
206 | 209 |
self._cache_result() |
207 | 210 |
raise |
... | ... | |
264 | 267 |
elif cacheable: cache_status = 'Cache miss' |
265 | 268 |
else: cache_status = 'Non-cacheable' |
266 | 269 |
self.log_debug(cache_status+': ' |
267 |
+strings.one_line(str(get_cur_query(cur, query)))) |
|
270 |
+strings.one_line(str(get_cur_query(cur, query, params))))
|
|
268 | 271 |
|
269 | 272 |
return cur |
270 | 273 |
|
Also available in: Unified diff
sql.py: get_cur_query(): Also accept input params to combine with input_query, and pass input params when get_cur_query() is called