def apply_limit_if_exists(database: Database, increased_limit: Optional[int], query: Query, sql: str) -> str: if query.limit and increased_limit: # We are fetching one more than the requested limit in order # to test whether there are more rows than the limit. # Later, the extra row will be dropped before sending # the results back to the user. sql = database.apply_limit_to_sql(sql, increased_limit, force=True) return sql