active_record: don't checkout connections unless necessary

Reported-by: Karol Bucek <self@kares.org>
Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
streamy_result_set: add ensure block to close connections

Reported-by: Karol Bucek <self@kares.org>
Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>