import sqlite3
import os

dbs = [
    "/app/companies_v4_notion_sync.db",
    "/app/companies_v3_final.db",
    "/app/company-explorer/companies_v3_fixed_2.db",
    "/app/company-explorer/companies.db"
]

found = False
for db_path in dbs:
    if not os.path.exists(db_path):
        continue
    
    print(f"Checking {db_path}...")
    try:
        conn = sqlite3.connect(db_path)
        cursor = conn.cursor()
        
        # Get column names
        cursor.execute("PRAGMA table_info(companies)")
        columns = [info[1] for info in cursor.fetchall()]
        print(f"Columns: {columns}")
        
        cursor.execute("SELECT * FROM companies WHERE name LIKE '%Wolfra%'")
        rows = cursor.fetchall()
        
        if rows:
            print(f"Found {len(rows)} rows in {db_path}:")
            for row in rows:
                # Create a dict for easier reading
                row_dict = dict(zip(columns, row))
                print(row_dict)
            found = True
        else:
            print("No matching rows found.")
            
        conn.close()
    except Exception as e:
        print(f"Error reading {db_path}: {e}")
    print("-" * 20)

if not found:
    print("No 'Wolfra' company found in any checked database.")
