Skip to content

Commit fc6647a

Browse files
committedDec 18, 2023
updated style
1 parent c73d1d2 commit fc6647a

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
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.2"
21+
version="9.3.3"
2222
)

‎src/cs50/sql.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,13 @@ def __init__(self, url, **kwargs):
7171
# without isolation_level, PostgreSQL warns with "there is already a transaction in progress" for our own BEGIN and
7272
# "there is no transaction in progress" for our own COMMIT
7373
self._engine = sqlalchemy.create_engine(url, **kwargs).execution_options(
74-
autocommit=False, isolation_level="AUTOCOMMIT"
74+
autocommit=False, isolation_level="AUTOCOMMIT", no_parameters=True
7575
)
7676

77+
# Avoid doubly escaping percent signs, since no_parameters=True anyway
78+
# https://github.com/cs50/python-cs50/issues/171
79+
self._engine.dialect.identifier_preparer._double_percents = False
80+
7781
# Get logger
7882
self._logger = logging.getLogger("cs50")
7983

@@ -559,12 +563,19 @@ def __escape(value):
559563

560564
# str
561565
elif isinstance(value, str):
566+
<<<<<<< HEAD
562567
return sqlparse.sql.Token(
563568
sqlparse.tokens.String,
564569
sqlalchemy.types.String().literal_processor(self._engine.dialect)(
565570
value
566571
),
567572
)
573+
=======
574+
literal = sqlalchemy.types.String().literal_processor(self._engine.dialect)(value)
575+
#if self._engine.dialect.identifier_preparer._double_percents:
576+
# literal = literal.replace("%%", "%")
577+
return sqlparse.sql.Token(sqlparse.tokens.String, literal)
578+
>>>>>>> 3863555 (fixes #171)
568579

569580
# None
570581
elif value is None:

‎tests/sql.py

+6
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ def test_lastrowid(self):
138138
self.assertEqual(self.db.execute("INSERT INTO foo (firstname, lastname) VALUES('firstname', 'lastname')"), 1)
139139
self.assertRaises(ValueError, self.db.execute, "INSERT INTO foo (id, firstname, lastname) VALUES(1, 'firstname', 'lastname')")
140140

141+
def test_url(self):
142+
url = "https://www.amazon.es/Desesperaci%C3%B3n-BEST-SELLER-Stephen-King/dp/8497595890"
143+
self.db.execute("CREATE TABLE foo(id SERIAL PRIMARY KEY, url TEXT)")
144+
self.db.execute("INSERT INTO foo (url) VALUES(?)", url)
145+
self.assertEqual(self.db.execute("SELECT url FROM foo")[0]["url"], url)
146+
141147
def tearDown(self):
142148
self.db.execute("DROP TABLE cs50")
143149
self.db.execute("DROP TABLE IF EXISTS foo")

0 commit comments

Comments
 (0)
Please sign in to comment.