#!/usr/bin/env python3
import sqlite3
import sys

p = sys.argv[1] if len(sys.argv) > 1 else "clash_cache.db"
con = sqlite3.connect(p)
for (name,) in con.execute("SELECT name FROM sqlite_master WHERE type='table'"):
    print("TABLE", name)
    cols = [c[1] for c in con.execute(f"PRAGMA table_info({name})")]
    print(" cols", cols)
    for row in con.execute(f"SELECT * FROM {name} LIMIT 8"):
        s = str(row)
        print(" ", s[:300] + ("..." if len(s) > 300 else ""))
