File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ def escape_float(value, mapping=None):
5959
6060_escape_table = [chr (x ) for x in range (128 )]
6161_escape_table [ord ("'" )] = u"''"
62+ _escape_table [ord ("\\ " )] = "\\ \\ "
6263
6364
6465def _escape_unicode (value , mapping = None ):
Original file line number Diff line number Diff line change @@ -90,6 +90,35 @@ def test_select_chdb_version(self):
9090 self .assertEqual (ver , "." .join (ver_tuple ))
9191 self .assertRegex (ver , expected_version_pattern )
9292
93+ def test_insert_escape_slash (self ):
94+ # make a tmp dir context
95+ with tempfile .TemporaryDirectory () as tmpdirname :
96+ conn = dbapi .connect (tmpdirname )
97+ print (conn )
98+ cur = conn .cursor ()
99+ # cur.execute("CREATE DATABASE IF NOT EXISTS test_db ENGINE = Atomic")
100+ # cur.execute("USE test_db")
101+ cur .execute (
102+ """
103+ CREATE TABLE tmp (
104+ s String
105+ ) ENGINE = Log"""
106+ )
107+
108+ # Insert single value
109+ s = "hello\\ 'world"
110+ print ("Inserting string: " , s )
111+ cur .execute ("INSERT INTO tmp VALUES (%s)" , (s ))
112+
113+ # Test fetchone
114+ cur .execute ("SELECT s FROM tmp" )
115+ row1 = cur .fetchone ()
116+ self .assertEqual (row1 [0 ], s )
117+
118+ # Clean up
119+ cur .close ()
120+ conn .close ()
121+
93122
94123if __name__ == "__main__" :
95124 unittest .main ()
You can’t perform that action at this time.
0 commit comments