Encode the query as UTF8 if given as unicode.