ECPG: Relax an overly restrictive constraint at the two ends of
the cursor result set leading to more fetches than necessary.
ECPG: Relax the previous check even more which also fixes computing
the position after the last tuple in some cases.

One regression test result (.stderr only) has changed.
ECPG: Rewrite the cursor readahead logic by extracting certain
common operations into their own functions.

This helps catching common errors from every MOVE and FETCH
operations.

A new regression test was added to test for the corner case
where the application constantly flipping the cursor position
from positive to negative and vice-versa. Allow serving this
case from the cache if possible.