import sqlite3
from pathlib import Path

# 定义路径
db_path = Path(__file__).resolve().parent / 'footviz' / 'data' / 'football_original.db'

def check_database_structure():
    """检查数据库结构"""
    conn = sqlite3.connect(db_path)
    cursor = conn.cursor()
    
    # 获取所有表名
    cursor.execute("SELECT name FROM sqlite_master WHERE type='table'")
    tables = cursor.fetchall()
    
    print("所有表:")
    for table in tables:
        print(f"  - {table[0]}")
        
    # 检查Players表结构
    print("\nPlayers表结构:")
    cursor.execute("PRAGMA table_info(Players)")
    columns = cursor.fetchall()
    for col in columns:
        print(f"  {col[1]} ({col[2]})")
        
    # 检查Teams表结构
    print("\nTeams表结构:")
    cursor.execute("PRAGMA table_info(Teams)")
    columns = cursor.fetchall()
    for col in columns:
        print(f"  {col[1]} ({col[2]})")
        
    # 检查PlayerStats表结构
    print("\nPlayerStats表结构:")
    cursor.execute("PRAGMA table_info(PlayerStats)")
    columns = cursor.fetchall()
    for col in columns:
        print(f"  {col[1]} ({col[2]})")
        
    # 检查几条PlayerStats记录
    print("\nPlayerStats示例数据:")
    cursor.execute("SELECT * FROM PlayerStats LIMIT 3")
    rows = cursor.fetchall()
    for row in rows:
        print(f"  {row}")
        
    # 检查是否有players_teams关联表
    print("\n检查是否存在players_teams关联表:")
    cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='players_teams'")
    result = cursor.fetchone()
    if result:
        print("  存在players_teams表")
        cursor.execute("PRAGMA table_info(players_teams)")
        columns = cursor.fetchall()
        print("  players_teams表结构:")
        for col in columns:
            print(f"    {col[1]} ({col[2]})")
    else:
        print("  不存在players_teams表")
    
    conn.close()

if __name__ == "__main__":
    check_database_structure()