Cursor Objects — PyMySQL 0.7.2 documentation https://pymysql.readthedocs.io/en/latest/modules/cursors.html#pymysql.cursors.Cursor.executemany

 

executemany(queryargs)

Run several data against one query

Parameters:
  • query – query to execute on server
  • args – Sequence of sequences or mappings. It is used as parameter.
Returns:

Number of rows affected, if any.

This method improves performance on multiple-row INSERT and REPLACE. Otherwise it is equivalent to looping over args with execute().

 


sql_a_executemany = 'INSERT INTO answer ({}) VALUES (%s,%s,%s)'.format(field_a_insert)

l = []
for k in d['a']:
qid, content, created = dbid, d['a'][k], tm
l.append((qid, content, created))
sql_executemany = {}
sql_executemany['sql'], sql_executemany['args'] = sql_a_executemany, l
mysql_write(sql_executemany, executemany=True)


if executemany:
cursor.executemany(sql['sql'], sql['args'])
else:
cursor.execute(sql)