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)
| 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 |