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 --- .../connection_adapters/abstract/database_statements.rb | 12 +++++++----- .../lib/active_record/connection_adapters/mysql_adapter.rb | 8 ++++---- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'activerecord/lib') 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