Commit ef232cd8 by 林冲

将值作为元组列表传递给 execute_batch_insert 方法

1 parent 3fcdf2e8
......@@ -84,6 +84,27 @@ class DBHelper:
self.logger.info(f"更新失败: {sql}, 错误: {e}")
raise
def execute_batch_insert(self, sql, values_list):
"""
执行批量插入SQL(使用参数化查询)
Args:
sql: 插入SQL语句模板(使用 %s 占位符)
values_list: 值列表,每个元素是一个元组
Returns:
bool: 执行成功返回True
"""
try:
self.logger.debug(f"执行批量插入: {sql}, 记录数: {len(values_list)}")
self.db.cursor.executemany(sql, values_list)
self.db.con.commit()
return True
except Exception as e:
self.logger.info(f"ERROR批量插入失败: {sql}, 错误: {e}")
self.db.con.rollback()
raise
def close(self):
"""关闭数据库连接"""
if self.db:
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!