File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 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):
288288 for table in table_names :
289289 cursor .execute ('DROP TABLE IF EXISTS {}' .format (table ))
290290
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+
291305 def test_get_schemas (self ):
292306 with self .cursor ({}) as cursor :
293307 database_name = 'db_{uuid}' .format (uuid = str (uuid4 ()).replace ('-' , '_' ))
You can’t perform that action at this time.
0 commit comments