private function get_limit_sql($sql, array $params = null, $limitfrom=0, $limitnum=0) {

        list($limitfrom, $limitnum) = $this->normalise_limit_from_num($limitfrom, $limitnum);
        // TODO: Add the /*+ FIRST_ROWS */ hint if there isn't another hint

        if ($limitfrom and $limitnum) {
            $sql = "SELECT oracle_o.*
                      FROM (SELECT oracle_i.*, rownum AS oracle_rownum
                              FROM ($sql) oracle_i
                             WHERE rownum <= :oracle_num_rows
                            ) oracle_o
                     WHERE oracle_rownum > :oracle_skip_rows";
            $params['oracle_num_rows'] = $limitfrom + $limitnum;
            $params['oracle_skip_rows'] = $limitfrom;

        } else if ($limitfrom and !$limitnum) {
            $sql = "SELECT oracle_o.*
                      FROM (SELECT oracle_i.*, rownum AS oracle_rownum
                              FROM ($sql) oracle_i
                            ) oracle_o
                     WHERE oracle_rownum > :oracle_skip_rows";
            $params['oracle_skip_rows'] = $limitfrom;

        } else if (!$limitfrom and $limitnum) {
            $sql = "SELECT *
                      FROM ($sql)
                     WHERE rownum <= :oracle_num_rows";
            $params['oracle_num_rows'] = $limitnum;
        }

        return array($sql, $params);
    }