import sqlite3, sys, io sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8") db = r"G:\WEB-SERVER\htdocs\AttendanceHub\ZKTecoSyncService-V2\publish\attendancehub_v2.db" con = sqlite3.connect("file:" + db.replace("\\", "/") + "?mode=ro", uri=True) cur = con.cursor() cur.execute("SELECT MIN(first_seen_at), MAX(first_seen_at), MIN(last_attempt_at), MAX(last_attempt_at) FROM client_dlq") r = cur.fetchone() print("DLQ_FIRST_SEEN_MIN=", r[0], sep="") print("DLQ_FIRST_SEEN_MAX=", r[1], sep="") print("DLQ_LAST_ATTEMPT_MIN=", r[2], sep="") print("DLQ_LAST_ATTEMPT_MAX=", r[3], sep="") # Distribution by last_attempt_at date-hour to identify this activation window cur.execute("SELECT substr(last_attempt_at,1,13) AS h, COUNT(*) FROM client_dlq GROUP BY h ORDER BY h") for row in cur.fetchall(): print(f"DLQ_BY_HOUR {row[0]}={row[1]}") # failure_class + resolution distribution cur.execute("SELECT failure_class, resolution, COUNT(*) FROM client_dlq GROUP BY failure_class, resolution") for row in cur.fetchall(): print(f"DLQ_CLASS {row[0]} resolution={row[1]} count={row[2]}") # Sample 3 rows (no payload_json) cur.execute("SELECT local_id, device_id, personnel_code, punch_time, first_seen_at, last_attempt_at, attempts FROM client_dlq ORDER BY local_id LIMIT 3") for row in cur.fetchall(): print("DLQ_SAMPLE:", row) # Check punches upload_state for any non Pending/Dlq rows and upload error distribution on Pending cur.execute("SELECT last_error_code, COUNT(*) FROM punches WHERE upload_state='Pending' GROUP BY last_error_code") for row in cur.fetchall(): print(f"PENDING_LAST_ERROR {row[0]}={row[1]}") # earliest/latest punch_time overall (for context) cur.execute("SELECT MIN(punch_time), MAX(punch_time) FROM punches") r = cur.fetchone() print("PUNCH_TIME_MIN=", r[0], sep="") print("PUNCH_TIME_MAX=", r[1], sep="") con.close()