MCPcopy Create free account
hub / github.com/PyMySQL/PyMySQL / executemany

Method executemany

pymysql/cursors.py:174–209  ·  view source on GitHub ↗

Run several data against one query. :param query: Query to execute. :type query: str :param args: Sequence of sequences or mappings. It is used as parameter. :type args: tuple or list :return: Number of rows affected, if any. :rtype: int or None

(self, query, args)

Source from the content-addressed store, hash-verified

172 return result
173
174 def executemany(self, query, args):
175 """Run several data against one query.
176
177 :param query: Query to execute.
178 :type query: str
179
180 :param args: Sequence of sequences or mappings. It is used as parameter.
181 :type args: tuple or list
182
183 :return: Number of rows affected, if any.
184 :rtype: int or None
185
186 This method improves performance on multiple-row INSERT and
187 REPLACE. Otherwise it is equivalent to looping over args with
188 execute().
189 """
190 if not args:
191 return
192
193 m = RE_INSERT_VALUES.match(query)
194 if m:
195 q_prefix = m.group(1) % ()
196 q_values = m.group(2).rstrip()
197 q_postfix = m.group(3) or ""
198 assert q_values[0] == "(" and q_values[-1] == ")"
199 return self._do_execute_many(
200 q_prefix,
201 q_values,
202 q_postfix,
203 args,
204 self.max_stmt_length,
205 self._get_db().encoding,
206 )
207
208 self.rowcount = sum(self.execute(query, arg) for arg in args)
209 return self.rowcount
210
211 def _do_execute_many(
212 self, prefix, values, postfix, args, max_stmt_length, encoding

Callers 8

test_bulk_insertMethod · 0.80
test_issue_288Method · 0.80
test_executemanyMethod · 0.80
test_SSCursorMethod · 0.80
test_issue_364Method · 0.80
setUpMethod · 0.80

Calls 3

_do_execute_manyMethod · 0.95
_get_dbMethod · 0.95
executeMethod · 0.95

Tested by 8

test_bulk_insertMethod · 0.64
test_issue_288Method · 0.64
test_executemanyMethod · 0.64
test_SSCursorMethod · 0.64
test_issue_364Method · 0.64
setUpMethod · 0.64