Revision 1901
Added by Aaron Marcuse-Kubitza almost 13 years ago
sql.py | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import copy |
4 | 4 |
import re |
5 |
import sys |
|
6 | 5 |
import warnings |
7 | 6 |
|
8 | 7 |
import exc |
... | ... | |
77 | 76 |
|
78 | 77 |
def _query_lookup(query, params): return (query, util.cast(tuple, params)) |
79 | 78 |
|
79 |
log_debug_none = lambda msg: None |
|
80 |
|
|
80 | 81 |
class DbConn: |
81 |
def __init__(self, db_config, serializable=True, debug=False):
|
|
82 |
def __init__(self, db_config, serializable=True, log_debug=log_debug_none):
|
|
82 | 83 |
self.db_config = db_config |
83 | 84 |
self.serializable = serializable |
84 |
self.debug = debug
|
|
85 |
self.log_debug = log_debug
|
|
85 | 86 |
|
86 | 87 |
self.__db = None |
87 | 88 |
self.pkeys = {} |
... | ... | |
161 | 162 |
except Exception, e: |
162 | 163 |
_add_cursor_info(e, cur) |
163 | 164 |
raise |
164 |
if self.debug:
|
|
165 |
sys.stderr.write(strings.one_line(get_cur_query(cur))+'\n')
|
|
165 |
if self.log_debug != log_debug_none: # only compute msg if needed
|
|
166 |
self.log_debug(strings.one_line(get_cur_query(cur)))
|
|
166 | 167 |
return cur |
167 | 168 |
else: return self.CacheCursor(actual_query, result) |
168 | 169 |
|
Also available in: Unified diff
sql.py: DbConn: Allow creator to provide a log function to call on debug messages, instead of using stderr directly