Fixed #17339 -- Factor out has_result into database backend.

Thanks jonash.