diff options
author | Emilio Tagua <miloops@gmail.com> | 2010-03-25 12:27:34 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2010-03-25 12:37:38 -0300 |
commit | e3a2fae05dfce39bbac86780c28b102acc3aa68f (patch) | |
tree | 49fb16b235edf44e74940ab0d93617ee6e9a9013 /activerecord/lib/active_record/connection_adapters/abstract | |
parent | ed21f0c50270139ddb6993acfdaea4586ffd09a3 (diff) | |
download | rails-e3a2fae05dfce39bbac86780c28b102acc3aa68f.tar.gz rails-e3a2fae05dfce39bbac86780c28b102acc3aa68f.tar.bz2 rails-e3a2fae05dfce39bbac86780c28b102acc3aa68f.zip |
Add add_limit_offset! to adapters.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb index abb695264e..0c87e052c4 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb @@ -181,6 +181,29 @@ module ActiveRecord # done if the transaction block raises an exception or returns false. def rollback_db_transaction() end + # 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 + # and an +:offset+ option. + # + # 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 + + def add_limit_offset!(sql, options) + if limit = options[:limit] + sql << " LIMIT #{sanitize_limit(limit)}" + end + if offset = options[:offset] + sql << " OFFSET #{offset.to_i}" + end + sql + end + def default_sequence_name(table, column) nil end |