Cursor Objects — PyMySQL 0.7.2 documentation https://pymysql.readthedocs.io/en/latest/modules/cursors.html#pymysql.cursors.Cursor.executemany
executemany
(query, args)
Run several data against one query
Parameters: |
|
---|---|
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)