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):
59
59
60
60
_escape_table = [chr (x ) for x in range (128 )]
61
61
_escape_table [ord ("'" )] = u"''"
62
+ _escape_table [ord ("\\ " )] = "\\ \\ "
62
63
63
64
64
65
def _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):
90
90
self .assertEqual (ver , "." .join (ver_tuple ))
91
91
self .assertRegex (ver , expected_version_pattern )
92
92
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
+
93
122
94
123
if __name__ == "__main__" :
95
124
unittest .main ()
You can’t perform that action at this time.
0 commit comments