- fetch_one 返回 None 时安全处理,total_rows 默认为 0 - total_rows 为 0 时提前返回,避免不必要的循环
@@ -58,7 +58,11 @@ class MySqlDatabaseHelper:
query = text(query)
# 获取总行数
- total_rows = self.fetch_one(count_query, params)[0]
+ result = self.fetch_one(count_query, params)
+ total_rows = result[0] if result is not None else 0
+
+ if total_rows == 0:
+ return data
page = 1
with tqdm(total=total_rows, desc="Loading data", unit="rows") as pbar: