import sqlite3
import os

BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
L2_PATH = os.path.join(BASE_DIR, 'database', 'L2', 'L2_Main.sqlite')

def check_jacky():
    print(f"Checking L2 database at: {L2_PATH}")
    conn = sqlite3.connect(L2_PATH)
    cursor = conn.cursor()
    
    search_term = 'jacky'
    print(f"\nSearching for '%{search_term}%' (Case Insensitive test):")
    
    # Standard LIKE
    cursor.execute("SELECT steam_id_64, username FROM dim_players WHERE username LIKE ?", (f'%{search_term}%',))
    results = cursor.fetchall()
    print(f"LIKE results: {len(results)}")
    for r in results:
        print(r)
        
    # Case insensitive explicit
    print("\nSearching with LOWER():")
    cursor.execute("SELECT steam_id_64, username FROM dim_players WHERE LOWER(username) LIKE LOWER(?)", (f'%{search_term}%',))
    results_lower = cursor.fetchall()
    print(f"LOWER() results: {len(results_lower)}")
    for r in results_lower:
        print(r)

    # Check jacky0987 specifically
    print("\nChecking specific username 'jacky0987':")
    cursor.execute("SELECT steam_id_64, username FROM dim_players WHERE username = 'jacky0987'")
    specific = cursor.fetchone()
    print(f"Specific match: {specific}")

    conn.close()

if __name__ == '__main__':
    check_jacky()
