def escape_like(query: str, escape_character: str) ->str:
    """
    Escape special characters that are used in SQL's LIKE and ILIKE.

    Chosen escape character is prepended to each occurrence of a special character.
    Escape character is considered a special character too.

    WARNING: Do not forget to specify escape character to SQLAlchemy when actually
    performing `like`s and `ilike`s:
    >>> escape_character = "~"
    >>> search_query = "99.5%"
    >>> search_query = escape_like(search_query, escape_character)
    >>> Record.query.like(search_query, escape=escape_character) # do not forget `escape`
    """
    assert len(escape_character) == 1
    cases = [escape_character, '%', '_']
    for case in cases:
        query = query.replace(case, escape_character + case)
    return query
