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

SQLite seems to deadlock in this case if unlock_notify is used.