summaryrefslogtreecommitdiff
path: root/apps/codestyle/codestyle-sql.py
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codestyle/codestyle-sql.py')
-rw-r--r--apps/codestyle/codestyle-sql.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/apps/codestyle/codestyle-sql.py b/apps/codestyle/codestyle-sql.py
index 5f0b7b490d..79f13241f3 100644
--- a/apps/codestyle/codestyle-sql.py
+++ b/apps/codestyle/codestyle-sql.py
@@ -209,8 +209,10 @@ def backtick_check(file: io, file_path: str) -> None:
# Find SQL clauses
pattern = re.compile(
- r'\b(SELECT|FROM|JOIN|WHERE|GROUP BY|ORDER BY|DELETE FROM|UPDATE|INSERT INTO|SET|REPLACE|REPLACE INTO)\s+([^;]+)',
- re.IGNORECASE)
+ r'\b(SELECT|FROM|JOIN|WHERE|GROUP BY|ORDER BY|DELETE FROM|UPDATE|INSERT INTO|SET|REPLACE|REPLACE INTO)\s+(.*?)(?=;$|(?=\b(?:WHERE|SET|VALUES)\b)|$)',
+ re.IGNORECASE | re.DOTALL
+ )
+
# Make sure to ignore values enclosed in single- and doublequotes
quote_pattern = re.compile(r"'(?:\\'|[^'])*'|\"(?:\\\"|[^\"])*\"")
@@ -219,17 +221,15 @@ def backtick_check(file: io, file_path: str) -> None:
# Ignore comments
if line.startswith('--'):
continue
-
- # Ignore SET variables with multiple lines
- if line.startswith('@'):
- continue
# Sanitize single- and doublequotes to prevent false positives
sanitized_line = quote_pattern.sub('', line)
matches = pattern.findall(sanitized_line)
for clause, content in matches:
- words = re.findall(r'\b[a-zA-Z_][a-zA-Z0-9_]*\b', content)
+ # Find all words and exclude @variables
+ words = re.findall(r'\b(?<!@)([a-zA-Z_][a-zA-Z0-9_]*)\b', content)
+
for word in words:
# Skip SQL keywords
if word.upper() in {"SELECT", "FROM", "JOIN", "WHERE", "GROUP", "BY", "ORDER",
@@ -237,6 +237,7 @@ def backtick_check(file: io, file_path: str) -> None:
"IN", "OR", "REPLACE"}:
continue
+ # Make sure the word is enclosed in backticks
if not re.search(rf'`{re.escape(word)}`', content):
print(f"Missing backticks around ({word}). {file_path} at line {line_number}")
check_failed = True