def get_fields(conn, db, tbl):
    """
    Construct fields list string for a SELECT.
    If a field is a binary type (BLOB, VARBINARY) then HEX() it.

    :param conn: MySQL connection.
    :type conn: Connection
    :param db: Database name.
    :type db: str
    :param tbl: Table name.
    :type tbl: str
    :return: A comma separated list of fields.
    :rtype: str
    """
    query = "SELECT COLUMN_NAME, DATA_TYPE " \
            "FROM information_schema.COLUMNS " \
            "WHERE TABLE_SCHEMA='{db}' AND TABLE_NAME='{tbl}' " \
            "ORDER BY ORDINAL_POSITION".format(db=db, tbl=tbl)
    cursor = conn.cursor()
    cursor.execute(query)

    fields = []
    for row in cursor.fetchall():
        col_name = row[0]
        col_type = row[1].lower()
        if col_type in ['tinyblob',
                        'mediumblob',
                        'blob',
                        'longblob',
                        'binary',
                        'varbinary']:
            col_name = 'HEX(%s)' % col_name

        fields.append(col_name)

    return ', '.join(fields)