瀏覽代碼

refactor: query stripping

version-14
Ankush Menat 3 年之前
committed by Ankush Menat
父節點
當前提交
c4ca58fedf
共有 2 個檔案被更改,包括 17 行新增2 行删除
  1. +2
    -2
      frappe/database/database.py
  2. +15
    -0
      frappe/tests/test_db.py

+ 2
- 2
frappe/database/database.py 查看文件

@@ -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


+ 15
- 0
frappe/tests/test_db.py 查看文件

@@ -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):


Loading…
取消
儲存