fix: remove mariadb specific comments from column

MariaDB has additional syntax for comments which are like python.
This commit is contained in:
Ankush Menat 2022-09-26 10:51:02 +05:30
parent 5330814d7a
commit 9c84d078fa

View file

@ -45,6 +45,7 @@ URL_NOTATION_PATTERN = re.compile(
) # background-image: url('/assets/...')
DURATION_PATTERN = re.compile(r"^(?:(\d+d)?((^|\s)\d+h)?((^|\s)\d+m)?((^|\s)\d+s)?)$")
HTML_TAG_PATTERN = re.compile("<[^>]+>")
MARIADB_SPECIFIC_COMMENT = re.compile(r"#.*")
class Weekday(Enum):
@ -1827,8 +1828,11 @@ def sanitize_column(column_name: str) -> None:
from frappe import _
regex = re.compile("^.*[,'();].*")
column_name = sqlparse.format(column_name, strip_comments=True, keyword_case="lower")
if frappe.db and frappe.db.db_type == "mariadb":
# strip mariadb specific comments which are like python single line comments
column_name = MARIADB_SPECIFIC_COMMENT.sub("", column_name)
blacklisted_keywords = [
"select",
"create",
@ -1844,6 +1848,7 @@ def sanitize_column(column_name: str) -> None:
def _raise_exception():
frappe.throw(_("Invalid field name {0}").format(column_name), frappe.DataError)
regex = re.compile("^.*[,'();].*")
if "ifnull" in column_name:
if regex.match(column_name):
# to avoid and, or