소스 검색

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()]


불러오는 중...
취소
저장