Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Adds support for 'CREATE VIEW' statement#176

Merged
rongxin-liu merged 1 commit intomaincs50/python-cs50:mainfrom
create-viewcs50/python-cs50:create-viewCopy head branch name to clipboard
Sep 29, 2023
Merged

Adds support for 'CREATE VIEW' statement#176
rongxin-liu merged 1 commit intomaincs50/python-cs50:mainfrom
create-viewcs50/python-cs50:create-viewCopy head branch name to clipboard

Conversation

@rongxin-liu
Copy link
Contributor

This PR handles the situation when CREATE VIEW AND SELECT are both present in the query.

@rongxin-liu rongxin-liu merged commit 955637c into main Sep 29, 2023
@rongxin-liu rongxin-liu deleted the create-view branch September 29, 2023 20:28
full_statement = full_statement.upper()

# set of possible commands
commands = {"BEGIN", "CREATE VIEW", "DELETE", "INSERT", "SELECT", "START", "UPDATE"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# set of possible commands
commands = {"BEGIN", "CREATE VIEW", "DELETE", "INSERT", "SELECT", "START", "UPDATE"}

# check if the full_statement starts with any command
Copy link
Member

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])
Copy link
Member

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?

ret = result.rowcount

# If CREATE VIEW, return True
elif command == "CREATE VIEW":
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.