q.append (" GROUP BY "+groupby);
q.append (prefix); q.append (groupby); q.append (" IS NOT NULL GROUP BY "+groupby);
    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) {	    q.append (prefix);	    String accessColumn = accessor == null ? otherType.getIDField () : accessor;	    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 ";	}	for (int i=0; i<constraints.length; i++) {	    q.append (prefix);	    constraints[i].addToQuery (q, home, nonvirtual);	    prefix = " AND ";	}	if (filter != null) {	    q.append (prefix);	    q.append (filter);	}	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 ();    }