import sqlite3, sys, json sys.stdout.reconfigure(encoding="utf-8", errors="replace") DB = r"E:/ProgramData/.workbuddy/workbuddy.db" c = sqlite3.connect(DB, timeout=15) c.execute("PRAGMA busy_timeout=8000") TARGET = ("deleted_at IS NULL AND status='ACTIVE' AND schedule_type='once' " "AND next_run_at IS NULL") n = c.execute(f"select count(*) from automations where {TARGET}").fetchone()[0] print("BEFORE_ONCE_ACTIVE_NO_NEXT =", n) print("TOTAL_ROWS =", c.execute("select count(*) from automations").fetchone()[0]) print("ACTIVE_ALL =", c.execute( "select count(*) from automations where deleted_at is null and status='ACTIVE'" ).fetchone()[0]) print("RECURRING_ACTIVE =", c.execute( "select count(*) from automations where deleted_at is null and status='ACTIVE' " "and schedule_type='recurring'").fetchone()[0]) print("--- group: schedule_type x status x next_run_is_null ---") for r in c.execute( "select schedule_type, status, (next_run_at is null), count(*) from automations " "where deleted_at is null group by 1,2,3 order by 1,2,3"): print(" ", r) print("--- target rows (full) ---") cols = [d[1] for d in c.execute("PRAGMA table_info(automations)")] print("COLUMNS =", cols) for r in c.execute(f"select * from automations where {TARGET}"): d = dict(zip(cols, r)) print(" ", json.dumps({k: d.get(k) for k in ("id", "name", "status", "schedule_type", "next_run_at", "created_at", "updated_at", "deleted_at")}, ensure_ascii=False)) print("INTEGRITY_BEFORE =", c.execute("PRAGMA integrity_check").fetchone()[0]) c.close()