q.append(" ORDER BY " + order);
q.append(" ORDER BY ").append(order);
    public String buildQuery(INode home, INode nonvirtual, String kstr, String pre,                             boolean useOrder) throws SQLException {        StringBuffer q = new StringBuffer();        String prefix = pre;        if (kstr != null && !isComplexReference()) {            q.append(prefix);            String accessColumn = (accessName == null) ? otherType.getIDField() : accessName;            q.append(otherType.getTableName());            q.append(".");            q.append(accessColumn);            q.append(" = ");            // check if column is string type and value needs to be quoted            if (otherType.needsQuotes(accessColumn)) {                q.append("'");                q.append(escape(kstr));                q.append("'");            } else {                q.append(escape(kstr));            }            prefix = " AND ";        }        // render the constraints and filter        renderConstraints(q, home, nonvirtual, prefix);        // add joined fetch constraints        ownType.addJoinConstraints(q, prefix);        // add group and order clauses        if (groupby != null) {            q.append(" GROUP BY " + groupby);            if (useOrder && (groupbyOrder != null)) {                q.append(" ORDER BY " + groupbyOrder);            }        } else if (useOrder && (order != null)) {            q.append(" ORDER BY " + order);        }        return q.toString();    }