该功能通过调用mySQLdb python库中的 cursor.executemany()函数完成批量处理。
今天用这个函数完成了批量插入
例程:

def test_insertDB(options):
    conn = database.Connection(host=options.mysql_host,
                               database=options.mysql_database,
                               user=options.mysql_user,
                               password=options.mysql_password
                               )
    sql = "insert into person(name, age, telephone) values(%s, %s, %s)"
    tmp = (('ninini', 89, '888999'), ('koko', 900, '999999'))
    conn.executemany(sql, tmp)


其他还有批量更新,批量查询估计没有测试
参考来源:
http://markmail.org/message/dzxuv65tlrfvpsau

 

相关文章:

  • 2022-02-27
  • 2021-08-02
  • 2022-02-24
  • 2021-11-03
  • 2021-11-13
  • 2021-11-03
猜你喜欢
  • 2022-12-23
  • 2021-12-20
  • 2022-12-23
  • 2021-06-08
  • 2021-08-29
  • 2021-11-17
  • 2021-05-09
相关资源
相似解决方案