fix up database query