Skip to content
Browse files

Optimization refactoring for add_limit_offset!. In partial fullfilmen…

…t of #1236.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2509 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 68a3220 commit 89733eaecffef3c1ad55345677411c872b1c99e4 Marcel Molina committed Oct 9, 2005
View
2 activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Optimization refactoring for add_limit_offset!. In partial fullfilment of #1236. [skaes@web.de]
+
* Add ability to get all siblings, including the current child, with acts_as_tree. Recloses #2140. [Michael Schuerig <michael@schuerig.de>]
* Add geometric type for postgresql adapter. #2233 [akaspick@gmail.com]
View
12 activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
@@ -73,8 +73,7 @@ def rollback_db_transaction() end
# Alias for #add_limit_offset!.
def add_limit!(sql, options)
- return unless options
- add_limit_offset!(sql, options)
+ add_limit_offset!(sql, options) if options
end
# Appends +LIMIT+ and +OFFSET+ options to a SQL statement.
@@ -84,9 +83,12 @@ def add_limit!(sql, options)
# generates
# SELECT * FROM suppliers LIMIT 10 OFFSET 50
def add_limit_offset!(sql, options)
- return if options[:limit].nil?
- sql << " LIMIT #{options[:limit]}"
- sql << " OFFSET #{options[:offset]}" if options.has_key?(:offset) and !options[:offset].nil?
+ if limit = options[:limit]
+ sql << " LIMIT #{limit}"
+ if offset = options[:offset]
+ sql << " OFFSET #{offset}"
+ end
+ end
end
end
end
View
8 activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -195,11 +195,11 @@ def rollback_db_transaction #:nodoc:
def add_limit_offset!(sql, options) #:nodoc
- if options[:limit]
- if options[:offset].blank?
- sql << " LIMIT #{options[:limit]}"
+ if limit = options[:limit]
+ unless offset = options[:offset]
+ sql << " LIMIT #{limit}"
else
- sql << " LIMIT #{options[:offset]}, #{options[:limit]}"
+ sql << " LIMIT #{offset}, #{limit}"
end
end
end

0 comments on commit 89733ea

Please sign in to comment.
Something went wrong with that request. Please try again.