Share code for caching  affected rows

Signed-off-by: Michal Čihař <michal@cihar.com>
Share code for getting mysql link object

Signed-off-by: Michal Čihař <michal@cihar.com>