import pymysql, configparser

cfg = configparser.ConfigParser()
cfg.read(r'c:\fuentes\proyectos delphi\RAUL_ASENCIO\GESTION\db_config.ini')

conn = pymysql.connect(
    host=cfg.get('Database', 'Server'),
    port=int(cfg.get('Database', 'Port', fallback=3306)),
    user=cfg.get('Database', 'User_Name'),
    password=cfg.get('Database', 'Password'),
    database=cfg.get('Database', 'Database'),
    charset='utf8mb4'
)

with conn.cursor() as cur:
    print('=== DESCRIBE ge_trabajadores_fichajes ===')
    cur.execute('DESCRIBE ge_trabajadores_fichajes')
    for row in cur.fetchall():
        print(f'{row[0]}: {row[1]}')

    print('\n=== DISTINCT centro / zonas in ge_trabajadores_fichajes ===')
    cur.execute('SELECT DISTINCT centro FROM ge_trabajadores_fichajes ORDER BY centro')
    for row in cur.fetchall():
        print(f'Centro: {row[0]}')

    print('\n=== DESCRIBE ge_trabajadores ===')
    cur.execute('DESCRIBE ge_trabajadores')
    for row in cur.fetchall():
        print(f'{row[0]}: {row[1]}')

    print('\n=== TABLES LIKE ge_%trabajador% ===')
    cur.execute("SHOW TABLES LIKE '%trabajador%'")
    for row in cur.fetchall():
        print(row[0])

    print('\n=== TABLES LIKE ge_%zona% OR %centro% OR %tienda% OR %grupo% ===')
    cur.execute("SHOW TABLES LIKE '%zona%'")
    for row in cur.fetchall():
        print('zona:', row[0])
    cur.execute("SHOW TABLES LIKE '%centro%'")
    for row in cur.fetchall():
        print('centro:', row[0])
    cur.execute("SHOW TABLES LIKE '%tienda%'")
    for row in cur.fetchall():
        print('tienda:', row[0])
    cur.execute("SHOW TABLES LIKE '%grupo%'")
    for row in cur.fetchall():
        print('grupo:', row[0])

conn.close()
