Fix possible race condition when getting db results.

Signed-off-by: Aron Cedercrantz <aron@cedercrantz.se>