Factored out common code in database backends.