refactor Query.getSQL()