Program: 51532
Project: 51532
Buggy source:
/** 
 * Generates the SQL statement to access the children of <code>member</code>. For example, <blockquote> <pre>SELECT "city" FROM "customer" WHERE "country" = 'USA' AND "state_province" = 'BC' GROUP BY "city"</pre> </blockquote> retrieves the children of the member <code>[Canada].[BC]</code>. <p>See also   {@link SqlTupleReader#makeLevelMembersSql}.
 */
String makeChildMemberSql(RolapMember member,Connection jdbcConnection,MemberChildrenConstraint constraint){
  SqlQuery sqlQuery=newQuery(jdbcConnection,"String_Node_Str" + member);
  constraint.addMemberConstraint(sqlQuery,member);
  RolapLevel[] levels=(RolapLevel[])hierarchy.getLevels();
  RolapLevel level=levels[member.getLevel().getDepth() + 1];
  hierarchy.addToFrom(sqlQuery,level.getKeyExp());
  String q=level.getKeyExp().getExpression(sqlQuery);
  sqlQuery.addSelect(q);
  sqlQuery.addGroupBy(q);
  constraint.addLevelConstraint(sqlQuery,level);
  if (level.hasCaptionColumn()) {
    MondrianDef.Expression captionExp=level.getCaptionExp();
    hierarchy.addToFrom(sqlQuery,captionExp);
    String captionSql=captionExp.getExpression(sqlQuery);
    sqlQuery.addSelect(captionSql);
    sqlQuery.addGroupBy(captionSql);
  }
  hierarchy.addToFrom(sqlQuery,level.getOrdinalExp());
  String orderBy=level.getOrdinalExp().getExpression(sqlQuery);
  sqlQuery.addOrderBy(orderBy);
  if (!orderBy.equals(q)) {
    sqlQuery.addGroupBy(orderBy);
  }
  RolapProperty[] properties=level.getRolapProperties();
  for (int j=0; j < properties.length; j++) {
    RolapProperty property=properties[j];
    final MondrianDef.Expression exp=property.getExp();
    hierarchy.addToFrom(sqlQuery,exp);
    final String s=exp.getExpression(sqlQuery);
    sqlQuery.addSelect(s);
    sqlQuery.addGroupBy(s);
  }
  return sqlQuery.toString();
}

Fixed version (ground truth):
/** 
 * Generates the SQL statement to access the children of <code>member</code>. For example, <blockquote> <pre>SELECT "city" FROM "customer" WHERE "country" = 'USA' AND "state_province" = 'BC' GROUP BY "city"</pre> </blockquote> retrieves the children of the member <code>[Canada].[BC]</code>. <p>See also   {@link SqlTupleReader#makeLevelMembersSql}.
 */
String makeChildMemberSql(RolapMember member,Connection jdbcConnection,MemberChildrenConstraint constraint){
  SqlQuery sqlQuery=newQuery(jdbcConnection,"String_Node_Str" + member);
  constraint.addMemberConstraint(sqlQuery,member);
  RolapLevel[] levels=(RolapLevel[])hierarchy.getLevels();
  RolapLevel level=levels[member.getLevel().getDepth() + 1];
  hierarchy.addToFrom(sqlQuery,level.getKeyExp());
  String q=level.getKeyExp().getExpression(sqlQuery);
  sqlQuery.addSelect(q);
  sqlQuery.addGroupBy(q);
  constraint.addLevelConstraint(sqlQuery,level);
  if (level.hasCaptionColumn()) {
    MondrianDef.Expression captionExp=level.getCaptionExp();
    hierarchy.addToFrom(sqlQuery,captionExp);
    String captionSql=captionExp.getExpression(sqlQuery);
    sqlQuery.addSelect(captionSql);
    sqlQuery.addGroupBy(captionSql);
  }
  hierarchy.addToFrom(sqlQuery,level.getOrdinalExp());
  String orderBy=level.getOrdinalExp().getExpression(sqlQuery);
  sqlQuery.addOrderBy(orderBy,true,false);
  if (!orderBy.equals(q)) {
    sqlQuery.addGroupBy(orderBy);
  }
  RolapProperty[] properties=level.getRolapProperties();
  for (int j=0; j < properties.length; j++) {
    RolapProperty property=properties[j];
    final MondrianDef.Expression exp=property.getExp();
    hierarchy.addToFrom(sqlQuery,exp);
    final String s=exp.getExpression(sqlQuery);
    sqlQuery.addSelect(s);
    sqlQuery.addGroupBy(s);
  }
  return sqlQuery.toString();
}