encode query result