code: private String logAndGetQueryText(FieldSearchQuery query,
                                        String[] resultFields) //2004.05.02 wdn5e
              throws SQLException, QueryParseException {
          StringBuffer queryText = new StringBuffer("SELECT");
          if (query.getType() == FieldSearchQuery.TERMS_TYPE) {
              queryText.append(" doFields.pid FROM doFields"
                      + getWhereClause(query.getTerms()));
          } else {
              StringBuffer resultFieldsString = new StringBuffer();
              if (resultFields.length > 0) {
                  String delimiter = " ";
                  for (String element : resultFields) {
                      String dbColumn = "doFields." + dcFixup(element);
                      resultFieldsString.append(delimiter + dbColumn);
                      delimiter = ", ";
                  }
              }
              queryText.append(resultFieldsString);
              queryText.append(" FROM doFields");
              queryText.append(getWhereClause(query.getConditions()));
              // disabled sorting: see bug 78
              //            queryText.append(" ORDER BY");
              //            queryText.append(resultFieldsString);
  
          }
          String qt = queryText.toString();
          logger.debug(qt);
          return qt;
      }
docs: 2004.05.02 wdn5e -- sort on selected fields