# File lib/will_paginate/finders/active_record.rb, line 55
    def paginate_by_sql(sql, options)
      WillPaginate::Collection.create(*wp_parse_options(options)) do |pager|
        query = sanitize_sql(sql.dup)
        original_query = query.dup
        # add limit, offset
        query << " LIMIT #{pager.per_page} OFFSET #{pager.offset}"
        # perfom the find
        pager.replace find_by_sql(query)
        
        unless pager.total_entries
          count_query = original_query.sub /\bORDER\s+BY\s+[\w`,\s]+$/mi, ''
          count_query = "SELECT COUNT(*) FROM (#{count_query})"
          
          unless ['oracle', 'oci'].include?(self.connection.adapter_name.downcase)
            count_query << ' AS count_table'
          end
          # perform the count query
          pager.total_entries = count_by_sql(count_query)
        end
      end
    end