[server] Don't run SQL query when iterating result set.

SQLite seems to deadlock in this case.