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

Thanks jonash.

https://code.djangoproject.com/ticket/17339