As I wrote, you adapted the limit necessary: If a normal use can produce 5000 records, you fixed the limit to 5000 (or slightly more) the purpose is to avoid that a jokester arranges to have a full table dump so that you do not want.
If this is not a problem, you delete the limit, but in this case, I strongly advise you to test an extreme case to make sure that the configuration accepts it.
For the range, you do you ask not the right question... Can you know the last line? Yes, it's $Line - 1 except if no record has been found.
If this is not a problem, you delete the limit, but in this case, I strongly advise you to test an extreme case to make sure that the configuration accepts it.
For the range, you do you ask not the right question... Can you know the last line? Yes, it's $Line - 1 except if no record has been found.