Revision 2168
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): |
|
20 |
if hasattr(cur, 'query'): return cur.query |
|
21 |
elif hasattr(cur, '_last_executed'): return cur._last_executed |
|
22 |
else: return None |
|
19 |
def get_cur_query(cur, input_query=None): |
|
20 |
raw_query = None |
|
21 |
if hasattr(cur, 'query'): raw_query = cur.query |
|
22 |
elif hasattr(cur, '_last_executed'): raw_query = cur._last_executed |
|
23 |
return util.coalesce(raw_query, input_query) |
|
23 | 24 |
|
24 |
def _add_cursor_info(e, cur): exc.add_msg(e, 'query: '+str(get_cur_query(cur))) |
|
25 |
def _add_cursor_info(e, cur, input_query=None): |
|
26 |
exc.add_msg(e, 'query: '+str(get_cur_query(cur, input_query))) |
|
25 | 27 |
|
26 | 28 |
class DbException(exc.ExceptionWithCause): |
27 | 29 |
def __init__(self, msg, cause=None, cur=None): |
... | ... | |
199 | 201 |
try: return_value = self.inner.execute(query, params) |
200 | 202 |
finally: self.query = get_cur_query(self.inner) |
201 | 203 |
except Exception, e: |
202 |
_add_cursor_info(e, self) |
|
204 |
_add_cursor_info(e, self, query)
|
|
203 | 205 |
self.result = e # cache the exception as the result |
204 | 206 |
self._cache_result() |
205 | 207 |
raise |
Also available in: Unified diff
sql.py: get_cur_query() and _add_cursor_info(): Support input_query param that will be used if the raw query is None. Pass input_query in DbConn.execute().