浏览代码

feat: allow WITH ... SELECT (CTE) SQL in query reports.

version-14
Carsten Tschense 3 年前
committed by Ankush Menat
父节点
当前提交
e833ef3a0d
共有 1 个文件被更改,包括 9 次插入2 次删除
  1. +9
    -2
      frappe/core/doctype/report/report.py

+ 9
- 2
frappe/core/doctype/report/report.py 查看文件

@@ -110,8 +110,15 @@ class Report(Document):
if not self.query:
frappe.throw(_("Must specify a Query to run"), title=_('Report Document Error'))

if not self.query.lower().startswith("select"):
frappe.throw(_("Query must be a SELECT"), title=_('Report Document Error'))
# Disallow SQL that writes to the database.
if (not self.query.lower().startswith("select") and
not self.query.lower().startswith("with")):
frappe.throw(_("Query must be a SELECT or WITH"), title=_('Report Document Error'))

# As of MariaDB 10.9, CTE WITH statements can only be combined with a SELECT clause and
# therefore are read-only. Postgres allows WITH ... INSERT INTO statements.
if (self.query.lower().startswith("with") and frappe.db.db_type != "mariadb"):
frappe.throw(_("WITH queries are only allowed for MariaDB databases"), title=_('Report Document Error'))

result = [list(t) for t in frappe.db.sql(self.query, filters)]
columns = self.get_columns() or [cstr(c[0]) for c in frappe.db.get_description()]


正在加载...
取消
保存