src/org/nutz/dao/util/Daos.java
public static long queryCount(Dao dao, Sql sql) {
        String tmpTable = "as _nutz_tmp";
        if (dao.meta().isDB2())
            tmpTable = "as nutz_tmp_" + R.UU32();
        else if (dao.meta().isOracle())
            tmpTable = "";
        else
            tmpTable += "_" + R.UU32();
        Sql sql2 = Sqls.fetchLong("select count(1) from (" + sql.getSourceSql() + ")" + tmpTable);
        sql2.setEntity(sql.getEntity());
        for (String key : sql.params().keys()) {
            sql2.setParam(key, sql.params().get(key));
        }
        for (String key : sql.vars().keys()) {
            sql2.setVar(key, sql.vars().get(key));
        }
        return dao.execute(sql2).getLong();
    }
public static long queryCount(Dao dao, Sql sql) {
        String tmpTable = "as _nutz_tmp";
        if (dao.meta().isDB2())
            tmpTable = "as nutz_tmp_" + R.UU32();
        else if (dao.meta().isOracle())
            tmpTable = "";
        else
            tmpTable += "_" + R.UU32();
        Sql sql2 = Sqls.fetchLong("select count(1) from (" + sql.getSourceSql() + ")" + tmpTable);
        sql2.setEntity(sql.getEntity());
        for (String key : sql.params().keys()) {
            sql2.setParam(key, sql.params().get(key));
        }
        for (String key : sql.vars().keys()) {
            sql2.setVar(key, sql.vars().get(key));
        }
        return dao.execute(sql2).getLong();
    }
查询某sql的结果条数
@param dao 用于执行该count方法的dao实例
@param sql 原本的Sql对象,将复制其sql语句,变量和参数表.