sb.append(" FROM ");  if (disableOuterJoins) sb.append(tableList); else { if (_alreadyJoined.count() > 0) { sb.append(joinClauseString()); } else { sb.append(tableList);
if(selectString.indexOf(" DISTINCT") != -1) { String [] columns = orderByClause.split(","); for(int i = 0; i < columns.length; i++) { String column = columns[i].replaceFirst("\\s+(ASC|DESC)\\s*", ""); if(columnList.indexOf(column) == -1) { sb.append(", "); sb.append(column); }
    public String assembleSelectStatementWithAttributes(NSArray attributes,                                                        boolean lock,                                                        EOQualifier qualifier,                                                        NSArray fetchOrder,                                                        String selectString,                                                        String columnList,                                                        String tableList,                                                        String whereClause,                                                        String joinClause,                                                        String orderByClause,                                                        String lockClause) {        StringBuffer sb = new StringBuffer();        sb.append(selectString);        sb.append(columnList);        sb.append(" FROM ");                if (disableOuterJoins)             sb.append(tableList);        else {            if (_alreadyJoined.count() > 0) {                sb.append(joinClauseString());            } else {                sb.append(tableList);            }        }        if ((whereClause != null && whereClause.length() > 0) ||            (disableOuterJoins && (joinClause != null && joinClause.length() > 0))) {            sb.append(" WHERE ");            if (joinClause != null && joinClause.length() > 0) {                sb.append(joinClause);                if (whereClause != null && whereClause.length() > 0)                    sb.append(" AND ");            }                        if (whereClause != null && whereClause.length() > 0) {                sb.append(whereClause);            }        }        if (orderByClause != null && orderByClause.length() > 0) {            sb.append(" ORDER BY ");            sb.append(orderByClause);        }        if (lockClause != null && lockClause.length() > 0) {            sb.append(" ");            sb.append(lockClause);        }        if (_fetchLimit != 0) {            sb.append(" LIMIT ");            sb.append(_fetchLimit);        }                return sb.toString();    }