Prevent access violation

Accessing an empty db.query result caused access violation. Prevention
by if statement for an empty result before.