import sqlite3, os, sys
sys.stdout.reconfigure(encoding='utf-8')

db = sqlite3.connect(os.path.join(os.environ['USERPROFILE'], '.local', 'share', 'opencode', 'opencode.db'))
cur = db.cursor()
cur.execute('PRAGMA table_info(session)')
cols = [r[1] for r in cur.fetchall()]
print('COLUMNS:', cols)
print()

q = """SELECT * FROM session"""
cur.execute(q)
rows = cur.fetchall()
print('TOTAL session rows:', len(rows))
for r in rows:
    d = dict(zip(cols, r))
    print(d.get('id'), '|', d.get('time_updated'), '|', d.get('directory'), '|', d.get('title'))
print()
try:
    cur.execute('PRAGMA table_info(session_v2)')
    cols2 = [x[1] for x in cur.fetchall()]
    cur.execute('SELECT * FROM session_v2')
    rows2 = cur.fetchall()
    print('TOTAL session_v2 rows:', len(rows2))
    for r in rows2:
        d = dict(zip(cols2, r))
        print(d.get('id'), '|', d.get('time_updated'), '|', d.get('directory'), '|', d.get('title'))
except Exception as e:
    print('session_v2 error:', e)
