refactor: query stripping

This commit is contained in:
Ankush Menat 2022-03-22 21:14:22 +05:30 committed by Ankush Menat
parent 456cba71cd
commit c4ca58fedf
2 changed files with 17 additions and 2 deletions

View file

@ -119,8 +119,8 @@ class Database(object):
if not run:
return query
# remove \n \t from start and end of query
query = re.sub(r'^\s*|\s*$', '', query)
# remove whitespace / indentation from start and end of query
query = query.strip()
if re.search(r'ifnull\(', query, flags=re.IGNORECASE):
# replaces ifnull in query with coalesce

View file

@ -312,6 +312,21 @@ class TestDB(unittest.TestCase):
frappe.db.MAX_WRITES_PER_TRANSACTION = Database.MAX_WRITES_PER_TRANSACTION
def test_transaction_write_counting(self):
note = frappe.get_doc(doctype="Note", title="transaction counting").insert()
writes = frappe.db.transaction_writes
frappe.db.set_value("Note", note.name, "content", "abc")
self.assertEqual(1, frappe.db.transaction_writes - writes)
writes = frappe.db.transaction_writes
frappe.db.sql("""
update `tabNote`
set content = 'abc'
where name = %s
""", note.name)
self.assertEqual(1, frappe.db.transaction_writes - writes)
def test_pk_collision_ignoring(self):
# note has `name` generated from title
for _ in range(3):