Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrapping drop/add in a transaction doesn't hurt #108

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions lib/geokit-rails/adapters/sqlserver.rb
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
module Geokit
module Adapters
class SQLServer < Abstract

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at class body beginning.

class << self

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at class body beginning.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at class body 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at class body end.

end
end
end
end