Bläddra i källkod

refactor: query stripping

version-14
Ankush Menat 3 år sedan
committed by Ankush Menat
förälder
incheckning
c4ca58fedf
2 ändrade filer med 17 tillägg och 2 borttagningar
  1. +2
    -2
      frappe/database/database.py
  2. +15
    -0
      frappe/tests/test_db.py

+ 2
- 2
frappe/database/database.py Visa fil

@@ -119,8 +119,8 @@ class Database(object):
if not run: if not run:
return query 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): if re.search(r'ifnull\(', query, flags=re.IGNORECASE):
# replaces ifnull in query with coalesce # replaces ifnull in query with coalesce


+ 15
- 0
frappe/tests/test_db.py Visa fil

@@ -312,6 +312,21 @@ class TestDB(unittest.TestCase):


frappe.db.MAX_WRITES_PER_TRANSACTION = Database.MAX_WRITES_PER_TRANSACTION 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): def test_pk_collision_ignoring(self):
# note has `name` generated from title # note has `name` generated from title
for _ in range(3): for _ in range(3):


Laddar…
Avbryt
Spara