Files
lm_code/check_db.py

23 lines
798 B
Python
Raw Normal View History

2026-02-15 02:16:45 +08:00
import sqlite3
import datetime
conn = sqlite3.connect(r'models\database.db')
c = conn.cursor()
tables = c.execute("SELECT name FROM sqlite_master WHERE type='table'").fetchall()
print("Tables:", [t[0] for t in tables])
for table in [t[0] for t in tables]:
try:
r = c.execute(f"SELECT MIN(id), MAX(id), COUNT(*) FROM [{table}]").fetchone()
if r[2] > 0 and r[0] and r[0] > 1000000000:
ts_min = r[0] // 1000 if r[0] > 1e12 else r[0]
ts_max = r[1] // 1000 if r[1] > 1e12 else r[1]
print(f" {table}: {r[2]} rows | {datetime.datetime.fromtimestamp(ts_min)} ~ {datetime.datetime.fromtimestamp(ts_max)}")
else:
print(f" {table}: {r[2]} rows")
except Exception as e:
print(f" {table}: error - {e}")
conn.close()