Fixed #21109 -- made db cursor error wrapping faster