instance method add_limit_offset!

Ruby on Rails 2.3.18

Since v2.2.3 Last seen in v3.1.12

Available in: v2.2.3 v2.3.18 v3.0.20 v3.1.12

Signature

add_limit_offset!(sql, options)

Appends LIMIT and OFFSET options to an SQL statement, or some SQL fragment that has the same semantics as LIMIT and OFFSET.

options must be a Hash which contains a :limit option (required) and an :offset option (optional).

This method modifies the sql parameter.

Examples
add_limit_offset!('SELECT * FROM suppliers', {:limit => 10, :offset => 50})

generates

SELECT * FROM suppliers LIMIT 10 OFFSET 50

Parameters

sql req
options req
Source
# File activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb, line 201
      def add_limit_offset!(sql, options)
        if limit = options[:limit]
          sql << " LIMIT #{sanitize_limit(limit)}"
          if offset = options[:offset]
            sql << " OFFSET #{offset.to_i}"
          end
        end
        sql
      end

Defined in activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb line 201 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::ConnectionAdapters::DatabaseStatements

Type at least 2 characters to search.

↑↓ navigate · open · esc close