-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from kwerle/feature/optional
Add an option to skip loading.
- Loading branch information
Showing
2 changed files
with
26 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,45 @@ | ||
module Geokit | ||
module Adapters | ||
class SQLServer < Abstract | ||
|
||
class << self | ||
|
||
def load(klass) | ||
klass.connection.execute <<-EOS | ||
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[geokit_least]') and xtype in (N'FN', N'IF', N'TF')) | ||
drop function [dbo].[geokit_least] | ||
EOS | ||
|
||
klass.connection.execute <<-EOS | ||
CREATE FUNCTION [dbo].geokit_least (@value1 float,@value2 float) RETURNS float AS BEGIN | ||
return (SELECT CASE WHEN @value1 < @value2 THEN @value1 ELSE @value2 END) END | ||
EOS | ||
klass.transaction do | ||
klass.connection.execute <<-EOS | ||
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[geokit_least]') and xtype in (N'FN', N'IF', N'TF')) | ||
drop function [dbo].[geokit_least] | ||
EOS | ||
|
||
klass.connection.execute <<-EOS | ||
CREATE FUNCTION [dbo].geokit_least (@value1 float,@value2 float) RETURNS float AS BEGIN | ||
return (SELECT CASE WHEN @value1 < @value2 THEN @value1 ELSE @value2 END) END | ||
EOS | ||
end | ||
self.loaded = true | ||
end | ||
|
||
end | ||
|
||
def initialize(*args) | ||
super(*args) | ||
end | ||
|
||
def sphere_distance_sql(lat, lng, multiplier) | ||
%| | ||
(ACOS([dbo].geokit_least(1,COS(#{lat})*COS(#{lng})*COS(RADIANS(#{qualified_lat_column_name}))*COS(RADIANS(#{qualified_lng_column_name}))+ | ||
COS(#{lat})*SIN(#{lng})*COS(RADIANS(#{qualified_lat_column_name}))*SIN(RADIANS(#{qualified_lng_column_name}))+ | ||
SIN(#{lat})*SIN(RADIANS(#{qualified_lat_column_name}))))*#{multiplier}) | ||
| | ||
end | ||
|
||
def flat_distance_sql(origin, lat_degree_units, lng_degree_units) | ||
%| | ||
SQRT(POWER(#{lat_degree_units}*(#{origin.lat}-#{qualified_lat_column_name}),2)+ | ||
POWER(#{lng_degree_units}*(#{origin.lng}-#{qualified_lng_column_name}),2)) | ||
| | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |