diff --git a/lib/active_record/connection_adapters/mysql2_adapter.rb b/lib/active_record/connection_adapters/mysql2_adapter.rb index 87f6ccf60..c61ff6de5 100644 --- a/lib/active_record/connection_adapters/mysql2_adapter.rb +++ b/lib/active_record/connection_adapters/mysql2_adapter.rb @@ -314,13 +314,13 @@ def release_savepoint end def add_limit_offset!(sql, options) - limit, offset = options[:limit], options[:offset] + limit, offset = options.fetch(:limit, 18446744073709551615), options[:offset] if limit && offset sql << " LIMIT #{offset.to_i}, #{sanitize_limit(limit)}" elsif limit sql << " LIMIT #{sanitize_limit(limit)}" elsif offset - sql << " OFFSET #{offset.to_i}" + sql << " LIMIT #{sanitize_limit(limit)} OFFSET #{offset.to_i}" end sql end