Skip to content

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

Merged
merged 1 commit into from
Sep 29, 2023
Merged

Adds support for 'CREATE VIEW' statement #176

merged 1 commit into from
Sep 29, 2023

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?

@@ -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":
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.

3 participants