From 89733eaecffef3c1ad55345677411c872b1c99e4 Mon Sep 17 00:00:00 2001 From: Marcel Molina Date: Sun, 9 Oct 2005 21:42:40 +0000 Subject: Optimization refactoring for add_limit_offset!. In partial fullfilment of #1236. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2509 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/CHANGELOG | 2 ++ .../connection_adapters/abstract/database_statements.rb | 12 +++++++----- .../lib/active_record/connection_adapters/mysql_adapter.rb | 8 ++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 809c567127..a181c89dde 100644 --- a/activerecord/CHANGELOG +++ b/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 ] * Add geometric type for postgresql adapter. #2233 [akaspick@gmail.com] 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 a3d22ed809..90dc951b6d 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb @@ -73,8 +73,7 @@ module ActiveRecord # 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 @@ module ActiveRecord # 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 diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index d56e1f90da..886363bcbe 100755 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -195,11 +195,11 @@ module ActiveRecord 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 -- cgit v1.2.3