MCPcopy
hub / github.com/PyMySQL/PyMySQL / executemany

Method executemany

pymysql/cursors.py:163–198  ·  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

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

Callers 13

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
test_executemanyMethod · 0.80
check_data_integrityMethod · 0.80
test_transactionsMethod · 0.80
test_truncationMethod · 0.80

Calls 3

_do_execute_manyMethod · 0.95
_get_dbMethod · 0.95
executeMethod · 0.95

Tested by 12

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
test_executemanyMethod · 0.64
test_transactionsMethod · 0.64
test_truncationMethod · 0.64