mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Allow leading comments on SQL queries, refs #1860
This commit is contained in:
parent
55f860c304
commit
af5d5d0243
2 changed files with 28 additions and 6 deletions
|
|
@ -205,13 +205,28 @@ class InvalidSql(Exception):
|
|||
pass
|
||||
|
||||
|
||||
# Allow SQL to start with a /* */ or -- comment
|
||||
comment_re = (
|
||||
# Start of string, then any amount of whitespace
|
||||
r"^(\s*"
|
||||
+
|
||||
# Comment that starts with -- and ends at a newline
|
||||
r"(?:\-\-.*?\n\s*)"
|
||||
+
|
||||
# Comment that starts with /* and ends with */
|
||||
r"|(?:/\*[\s\S]*?\*/)"
|
||||
+
|
||||
# Whitespace
|
||||
r")*\s*"
|
||||
)
|
||||
|
||||
allowed_sql_res = [
|
||||
re.compile(r"^select\b"),
|
||||
re.compile(r"^explain\s+select\b"),
|
||||
re.compile(r"^explain\s+query\s+plan\s+select\b"),
|
||||
re.compile(r"^with\b"),
|
||||
re.compile(r"^explain\s+with\b"),
|
||||
re.compile(r"^explain\s+query\s+plan\s+with\b"),
|
||||
re.compile(comment_re + r"select\b"),
|
||||
re.compile(comment_re + r"explain\s+select\b"),
|
||||
re.compile(comment_re + r"explain\s+query\s+plan\s+select\b"),
|
||||
re.compile(comment_re + r"with\b"),
|
||||
re.compile(comment_re + r"explain\s+with\b"),
|
||||
re.compile(comment_re + r"explain\s+query\s+plan\s+with\b"),
|
||||
]
|
||||
allowed_pragmas = (
|
||||
"database_list",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue