# 批量插入数据
def addinsertall(val):
db = sql.init()
cur = db.cursor()
val = [(
11,
22,
33,
44,
55,
66
)]
vsql = "INSERT INTO oct_itemprice (tid, price, couponprice, tkrates, type, time) VALUES (%s, %s, %s, %s, %s, %s)"
try:
cur.executemany(vsql, val)
db.commit()
except Exception as e:
sql.log('批量插入异常', e)
db.rollback()
finally:
cur.close()
db.close()
sql.log('本次批量插入成功' + str(cur.rowcount) + '条数据')
return cur.rowcount
python pymysql批量插入数据
python pymysql批量插入数据
# 批量插入数据
def addinsertall(val):
db = sql.init()
cur = db.cursor()
val = [(
11,
22,
33,
44,
55,
66
)]
vsql = "INSERT INTO oct_itemprice (tid, price, couponprice, tkrates, type, time) VALUES (%s, %s, %s, %s, %s, %s)"
try:
cur.executemany(vsql, val)
db.commit()
except Exception as e:
sql.log('批量插入异常', e)
db.rollback()
finally:
cur.close()
db.close()
sql.log('本次批量插入成功' + str(cur.rowcount) + '条数据')
return cur.rowcount