Adds support for 'CREATE VIEW' statement#176
Merged
rongxin-liu merged 1 commit intomaincs50/python-cs50:mainfrom Sep 29, 2023
Merged
Adds support for 'CREATE VIEW' statement#176rongxin-liu merged 1 commit intomaincs50/python-cs50:mainfrom
rongxin-liu merged 1 commit intomaincs50/python-cs50:mainfrom
Conversation
CarterZenke
approved these changes
Sep 29, 2023
dmalan
reviewed
Sep 29, 2023
| full_statement = full_statement.upper() | ||
|
|
||
| # set of possible commands | ||
| commands = {"BEGIN", "CREATE VIEW", "DELETE", "INSERT", "SELECT", "START", "UPDATE"} |
Member
There was a problem hiding this comment.
Will https://github.com/cs50/python-cs50/pull/176/files#diff-d12a5fb846ae94c77fc681c21dd86952fa2213c659ec05fe213dbe4e47468056R139 normalize whitespace, even if user provides, e.g., CREATE VIEW?
dmalan
reviewed
Sep 29, 2023
| # set of possible commands | ||
| commands = {"BEGIN", "CREATE VIEW", "DELETE", "INSERT", "SELECT", "START", "UPDATE"} | ||
|
|
||
| # check if the full_statement starts with any command |
dmalan
reviewed
Sep 29, 2023
| 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]) |
Member
There was a problem hiding this comment.
Seems unnecessary to flatten whole statement if you only need first 1–2 tokens?
dmalan
reviewed
Sep 29, 2023
| ret = result.rowcount | ||
|
|
||
| # If CREATE VIEW, return True | ||
| elif command == "CREATE VIEW": |
Member
There was a problem hiding this comment.
Why special-case CREATE VIEW instead of just CREATE for, e.g., CREATE TABLE also?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR handles the situation when
CREATE VIEWANDSELECTare both present in the query.