-
Notifications
You must be signed in to change notification settings - Fork 279
Adds support for 'CREATE VIEW' statement #176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
full_statement = full_statement.upper() | ||
|
||
# set of possible commands | ||
commands = {"BEGIN", "CREATE VIEW", "DELETE", "INSERT", "SELECT", "START", "UPDATE"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will https://github.com/cs50/python-cs50/pull/176/files#diff-d12a5fb846ae94c77fc681c21dd86952fa2213c659ec05fe213dbe4e47468056R139 normalize whitespace, even if user provides, e.g., CREATE VIEW
?
# set of possible commands | ||
commands = {"BEGIN", "CREATE VIEW", "DELETE", "INSERT", "SELECT", "START", "UPDATE"} | ||
|
||
# check if the full_statement starts with any command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Check if...
for PEP
else: | ||
command = None | ||
# Infer command from flattened statement to a single string separated by spaces | ||
full_statement = ' '.join(str(token) for token in statements[0].tokens if token.ttype in [sqlparse.tokens.Keyword, sqlparse.tokens.Keyword.DDL, sqlparse.tokens.Keyword.DML]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems unnecessary to flatten whole statement if you only need first 1–2 tokens?
@@ -393,6 +393,10 @@ def teardown_appcontext(exception): | |||
elif command in ["DELETE", "UPDATE"]: | |||
ret = result.rowcount | |||
|
|||
# If CREATE VIEW, return True | |||
elif command == "CREATE VIEW": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why special-case CREATE VIEW
instead of just CREATE
for, e.g., CREATE TABLE
also?
This PR handles the situation when
CREATE VIEW
ANDSELECT
are both present in the query.