fix(minor): mogrify
This commit is contained in:
parent
eba6dfa12a
commit
c83a9a142b
2 changed files with 11 additions and 8 deletions
|
|
@ -291,7 +291,7 @@ def errprint(msg):
|
|||
error_log.append({"exc": msg})
|
||||
|
||||
def print_sql(enable=True):
|
||||
return cache().set_value('print_sql', enable)
|
||||
return cache().set_value('flag_print_sql', enable)
|
||||
|
||||
def log(msg):
|
||||
"""Add to `debug_log`.
|
||||
|
|
|
|||
|
|
@ -193,23 +193,26 @@ class Database(object):
|
|||
return self._cursor.fetchall()
|
||||
|
||||
def log_query(self, query, values, debug, explain):
|
||||
def mogirfy():
|
||||
try:
|
||||
return self._cursor.mogrify(query, values)
|
||||
except TypeError:
|
||||
return [query, values]
|
||||
|
||||
# for debugging in tests
|
||||
if frappe.flags.in_test and frappe.cache().get_value('print_sql'):
|
||||
print(self._cursor.mogrify(query, values))
|
||||
if frappe.flags.in_test and frappe.cache().get_value('flag_print_sql'):
|
||||
print(mogrify())
|
||||
|
||||
# debug
|
||||
if debug:
|
||||
if explain and query.strip().lower().startswith('select'):
|
||||
self.explain_query(query, values)
|
||||
frappe.errprint(self._cursor.mogrify(query, values))
|
||||
frappe.errprint(mogrify())
|
||||
|
||||
# info
|
||||
if (frappe.conf.get("logging") or False)==2:
|
||||
frappe.log("<<<< query")
|
||||
frappe.log(query)
|
||||
if values:
|
||||
frappe.log("with values:")
|
||||
frappe.log(values)
|
||||
frappe.log(mogrify())
|
||||
frappe.log(">>>>")
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue