Skip to content

Commit e75afaf

Browse files
authoredOct 15, 2024··
Merge pull request #186 from cs50/vacuum
Adds support for `VACUUM`, fixes raw strings
2 parents d67a26b + f81a0a3 commit e75afaf

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed
 

‎setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
package_dir={"": "src"},
1919
packages=["cs50"],
2020
url="https://github.com/cs50/python-cs50",
21-
version="9.3.4"
21+
version="9.4.0"
2222
)

‎src/cs50/sql.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ def execute(self, sql, *args, **kwargs):
177177
"SELECT",
178178
"START",
179179
"UPDATE",
180+
"VACUUM",
180181
}
181182

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

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

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

380381
# Check for start of transaction
381-
if command in ["BEGIN", "START"]:
382+
if command in ["BEGIN", "START", "VACUUM"]: # cannot VACUUM from within a transaction
382383
self._autocommit = False
383384

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

391392
# Check for end of transaction
392-
if command in ["COMMIT", "ROLLBACK"]:
393+
if command in ["COMMIT", "ROLLBACK", "VACUUM"]: # cannot VACUUM from within a transaction
393394
self._autocommit = True
394395

395396
# Return value

0 commit comments

Comments
 (0)
Please sign in to comment.