fix bugs on DB query string