From dfb6d8175cd10a6acabe63d547bc9697f1acfd55 Mon Sep 17 00:00:00 2001
From: Alex Reisner <alex@alexreisner.com>
Date: Thu, 3 Jun 2010 08:55:50 -0400
Subject: [PATCH] Use separate :offset and :limit query options.
PostgreSQL doesn't support the "X,Y" format for the LIMIT clause, and this
is proper use of ActiveRecord anyway.
In response to bug reported by Github user kenzie.
---
lib/geocoder.rb | 18 +++++-------------
1 file changed, 5 insertions(+), 13 deletions(-)
diff --git a/lib/geocoder.rb b/lib/geocoder.rb
index 50f8dffd..25f7aaab 100644
--- a/lib/geocoder.rb
+++ b/lib/geocoder.rb
@@ -51,7 +51,7 @@ module Geocoder
#
# +order+ :: column(s) for ORDER BY SQL clause
# +limit+ :: number of records to return (for LIMIT SQL clause)
- # +offset+ :: number of records to skip (for LIMIT SQL clause)
+ # +offset+ :: number of records to skip (for OFFSET SQL clause)
#
def near_scope_options(latitude, longitude, radius = 20, options = {})
if ActiveRecord::Base.connection.adapter_name == "SQLite"
@@ -88,7 +88,8 @@ module Geocoder
coordinate_bounds(latitude, longitude, radius),
:having => "#{distance} <= #{radius}",
:order => options[:order],
- :limit => limit_clause(options)
+ :limit => options[:limit],
+ :offset => options[:offset]
}
end
@@ -106,7 +107,8 @@ module Geocoder
["#{lat_attr} BETWEEN ? AND ? AND #{lon_attr} BETWEEN ? AND ?"] +
coordinate_bounds(latitude, longitude, radius),
:order => options[:order],
- :limit => limit_clause(options)
+ :limit => options[:limit],
+ :offset => options[:offset]
}
end
@@ -125,16 +127,6 @@ module Geocoder
longitude + (radius / factor)
]
end
-
- ##
- # Build the limit clause for a query based on the same options hash
- # passed to the x_near_scope_options methods.
- #
- def limit_clause(options)
- if options[:limit] or options[:offset]
- "#{options[:offset].to_i},#{options[:limit].to_i}"
- end
- end
end
##
--
GitLab