if(s.isDistinct()) sb.append("distinct\n\t");
ValueNumber top = s.getTop();
if(top!=null) sb.append("top "+top.getString()+"\n\t");
// select
Expression[] sels = s.getSelects();
Expression exp;
boolean first=true;
for(int i=0;i<sels.length;i++) {
if(!first)sb.append("\t,");
exp=sels[i];
sb.append(exp.toString(false)+"\n");
first=false;
}
// from
sb.append("from\n\t");
Column[] forms = s.getFroms();
first=true;
for(int i=0;i<forms.length;i++) {
if(!first)sb.append("\t,");
exp=forms[i];
sb.append(exp.toString(false)+"\n");
first=false;
}
// where
if(s.getWhere()!=null){
sb.append("where \n\t");
sb.append(s.getWhere().toString(true));
sb.append("\n");
}
// group by
Column[] gbs = s.getGroupbys();
if(gbs.length>0) {
sb.append("group by\n\t");
first=true;
for(int i=0;i<gbs.length;i++) {
if(!first)sb.append("\t,");
exp=gbs[i];
sb.append(exp.toString(false)+"\n");
first=false;
}
}
// having
Operation having = s.getHaving();
if(having!=null){
sb.append("having \n\t");
sb.append(having.toString(true));
sb.append("\n");
}
}
// order by
if(__selects.orderbys!=null && __selects.orderbys.size()>0) {
sb.append("order by\n\t");
Iterator<Column> it = __selects.orderbys.iterator();
Expression exp;
boolean first = true;
while(it.hasNext()) {
if(!first)sb.append("\t,");
exp=it.next();
sb.append(exp.toString(false)+" "+(exp.isDirectionBackward()?"DESC":"ASC")+"\n");
first=false;
}
}
return sb.toString();
}