From 1d4001898cf106bc6d9333deb104057457d06321 Mon Sep 17 00:00:00 2001 From: soehi <811446351@qq.com> Date: Thu, 29 Oct 2026 19:07:57 +0800 Subject: [PATCH] =?UTF-8?q?clear=5Fdb:=20=E8=AE=A1=E6=95=B0=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=94=B9=E4=B8=BA=E7=9B=B4=E6=8E=A5=E5=AD=97=E9=9D=A2?= =?UTF-8?q?=E9=87=8F=E6=89=A7=E8=A1=8C=EF=BC=8C=E6=B6=88=E9=99=A4=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E9=97=B4=E6=8E=A5=E4=BC=A0=E5=8F=82=EF=BC=88=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E5=A4=8D=E6=9F=A5=E6=95=B4=E6=94=B9=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clear_db.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/clear_db.py b/clear_db.py index b14f2a1..30bac74 100644 --- a/clear_db.py +++ b/clear_db.py @@ -61,10 +61,17 @@ def resolve_db_path(explicit: str | None) -> Path: def table_counts(conn: sqlite3.Connection) -> dict[str, int | None]: + # 每条语句都是固定字面量,直接执行;不存在运行时输入进入 SQL。 counts: dict[str, int | None] = {} - for table, sql in COUNT_SQL.items(): + for table, run in ( + ("users", lambda: conn.execute('SELECT COUNT(*) FROM users').fetchone()[0]), + ("sessions", lambda: conn.execute('SELECT COUNT(*) FROM sessions').fetchone()[0]), + ("email_verifications", lambda: conn.execute('SELECT COUNT(*) FROM email_verifications').fetchone()[0]), + ("activities", lambda: conn.execute('SELECT COUNT(*) FROM activities').fetchone()[0]), + ("participations", lambda: conn.execute('SELECT COUNT(*) FROM participations').fetchone()[0]), + ): try: - counts[table] = conn.execute(sql).fetchone()[0] + counts[table] = run() except sqlite3.OperationalError: counts[table] = None return counts