Skip to content

Commit

Permalink
Merge pull request #186 from cs50/vacuum
Browse files Browse the repository at this point in the history
Adds support for `VACUUM`, fixes raw strings
  • Loading branch information
rongxin-liu authored Oct 15, 2024
2 parents d67a26b + f81a0a3 commit e75afaf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
package_dir={"": "src"},
packages=["cs50"],
url="https://github.com/cs50/python-cs50",
version="9.3.4"
version="9.4.0"
)
9 changes: 5 additions & 4 deletions src/cs50/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def execute(self, sql, *args, **kwargs):
"SELECT",
"START",
"UPDATE",
"VACUUM",
}

# Check if the full_statement starts with any command
Expand Down Expand Up @@ -328,12 +329,12 @@ def execute(self, sql, *args, **kwargs):
sqlparse.tokens.Literal.String,
sqlparse.tokens.Literal.String.Single,
]:
token.value = re.sub("(^'|\s+):", r"\1\:", token.value)
token.value = re.sub(r"(^'|\s+):", r"\1\:", token.value)

# In identifier
# https://www.sqlite.org/lang_keywords.html
elif token.ttype == sqlparse.tokens.Literal.String.Symbol:
token.value = re.sub('(^"|\s+):', r"\1\:", token.value)
token.value = re.sub(r'(^"|\s+):', r"\1\:", token.value)

# Join tokens into statement
statement = "".join([str(token) for token in tokens])
Expand Down Expand Up @@ -378,7 +379,7 @@ def teardown_appcontext(exception):
)

# Check for start of transaction
if command in ["BEGIN", "START"]:
if command in ["BEGIN", "START", "VACUUM"]: # cannot VACUUM from within a transaction
self._autocommit = False

# Execute statement
Expand All @@ -389,7 +390,7 @@ def teardown_appcontext(exception):
connection.execute(sqlalchemy.text("COMMIT"))

# Check for end of transaction
if command in ["COMMIT", "ROLLBACK"]:
if command in ["COMMIT", "ROLLBACK", "VACUUM"]: # cannot VACUUM from within a transaction
self._autocommit = True

# Return value
Expand Down

0 comments on commit e75afaf

Please sign in to comment.