Multiple iterations over buffered result set

Unit test and fix for issue #6845