@@ -136,37 +136,45 @@ def test_string_query_param(trino_connection):
136
136
137
137
138
138
def test_execute_many (trino_connection ):
139
- cur = trino_connection .cursor ()
140
- cur .execute ("CREATE TABLE memory.default.test_execute_many (key int, value varchar)" )
141
- cur .fetchall ()
142
- operation = "INSERT INTO memory.default.test_execute_many (key, value) VALUES (?, ?)"
143
- cur .executemany (operation , [(1 , "value1" )])
144
- cur .fetchall ()
145
- cur .execute ("SELECT * FROM memory.default.test_execute_many ORDER BY key" )
146
- rows = cur .fetchall ()
147
- assert len (list (rows )) == 1
148
- assert rows [0 ] == [1 , "value1" ]
139
+ try :
140
+ cur = trino_connection .cursor ()
141
+ cur .execute ("CREATE TABLE memory.default.test_execute_many (key int, value varchar)" )
142
+ cur .fetchall ()
143
+ operation = "INSERT INTO memory.default.test_execute_many (key, value) VALUES (?, ?)"
144
+ cur .executemany (operation , [(1 , "value1" )])
145
+ cur .fetchall ()
146
+ cur .execute ("SELECT * FROM memory.default.test_execute_many ORDER BY key" )
147
+ rows = cur .fetchall ()
148
+ assert len (list (rows )) == 1
149
+ assert rows [0 ] == [1 , "value1" ]
149
150
150
- operation = "INSERT INTO memory.default.test_execute_many (key, value) VALUES (?, ?)"
151
- cur .executemany (operation , [(2 , "value2" ), (3 , "value3" )])
152
- cur .fetchall ()
151
+ operation = "INSERT INTO memory.default.test_execute_many (key, value) VALUES (?, ?)"
152
+ cur .executemany (operation , [(2 , "value2" ), (3 , "value3" )])
153
+ cur .fetchall ()
153
154
154
- cur .execute ("SELECT * FROM memory.default.test_execute_many ORDER BY key" )
155
- rows = cur .fetchall ()
156
- assert len (list (rows )) == 3
157
- assert rows [0 ] == [1 , "value1" ]
158
- assert rows [1 ] == [2 , "value2" ]
159
- assert rows [2 ] == [3 , "value3" ]
155
+ cur .execute ("SELECT * FROM memory.default.test_execute_many ORDER BY key" )
156
+ rows = cur .fetchall ()
157
+ assert len (list (rows )) == 3
158
+ assert rows [0 ] == [1 , "value1" ]
159
+ assert rows [1 ] == [2 , "value2" ]
160
+ assert rows [2 ] == [3 , "value3" ]
161
+ finally :
162
+ cur = trino_connection .cursor ()
163
+ cur .execute ("DROP TABLE IF EXISTS memory.default.test_execute_many" )
160
164
161
165
162
166
def test_execute_many_without_params (trino_connection ):
163
- cur = trino_connection .cursor ()
164
- cur .execute ("CREATE TABLE memory.default.test_execute_many_without_param (value varchar)" )
165
- cur .fetchall ()
166
- with pytest .raises (TrinoUserError ) as e :
167
- cur .executemany ("INSERT INTO memory.default.test_execute_many_without_param (value) VALUES (?)" , [])
167
+ try :
168
+ cur = trino_connection .cursor ()
169
+ cur .execute ("CREATE TABLE memory.default.test_execute_many_without_param (value varchar)" )
168
170
cur .fetchall ()
169
- assert "Incorrect number of parameters: expected 1 but found 0" in str (e .value )
171
+ with pytest .raises (TrinoUserError ) as e :
172
+ cur .executemany ("INSERT INTO memory.default.test_execute_many_without_param (value) VALUES (?)" , [])
173
+ cur .fetchall ()
174
+ assert "Incorrect number of parameters: expected 1 but found 0" in str (e .value )
175
+ finally :
176
+ cur = trino_connection .cursor ()
177
+ cur .execute ("DROP TABLE IF EXISTS memory.default.test_execute_many_without_param" )
170
178
171
179
172
180
def test_execute_many_select (trino_connection ):
0 commit comments