File tree 1 file changed +14
-0
lines changed
1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -288,6 +288,20 @@ def test_get_columns(self):
288
288
for table in table_names :
289
289
cursor .execute ('DROP TABLE IF EXISTS {}' .format (table ))
290
290
291
+ def test_escape_single_quotes (self ):
292
+ with self .cursor ({}) as cursor :
293
+ table_name = 'table_{uuid}' .format (uuid = str (uuid4 ()).replace ('-' , '_' ))
294
+ # Test escape syntax directly
295
+ cursor .execute ("CREATE TABLE IF NOT EXISTS {} AS (SELECT 'you\\ 're' AS col_1)" .format (table_name ))
296
+ cursor .execute ("SELECT * FROM {} WHERE col_1 LIKE 'you\\ 're'" .format (table_name ))
297
+ rows = cursor .fetchall ()
298
+ assert rows [0 ]["col_1" ] == "you're"
299
+
300
+ # Test escape syntax in parameter
301
+ cursor .execute ("SELECT * FROM {} WHERE {}.col_1 LIKE %(var)s" .format (table_name , table_name ), parameters = {"var" : "you're" })
302
+ rows = cursor .fetchall ()
303
+ assert rows [0 ]["col_1" ] == "you're"
304
+
291
305
def test_get_schemas (self ):
292
306
with self .cursor ({}) as cursor :
293
307
database_name = 'db_{uuid}' .format (uuid = str (uuid4 ()).replace ('-' , '_' ))
You can’t perform that action at this time.
0 commit comments