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