Skip to content

Commit

Permalink
Support DSN'less connections. Resolves ticket 38.
Browse files Browse the repository at this point in the history
  • Loading branch information
metaskills committed Sep 14, 2010
1 parent ed79da8 commit a99c5f9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/active_record/connection_adapters/sqlserver_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,15 @@ def connect
@connection = case @connection_options[:mode]
when :odbc
odbc = ['::ODBC','::ODBC_UTF8','::ODBC_NONE'].detect{ |odbc_ns| odbc_ns.constantize rescue nil }.constantize
odbc.connect(config[:dsn], config[:username], config[:password]).tap do |c|
if config[:dsn].include?(';')
driver = odbc::Driver.new.tap do |d|
d.name = config[:dsn_name] || 'Driver1'
driver.attrs = dsn.split(';').map{ |atr| atr.split('=') }.reject{ |kv| kv.size != 2 }.inject({}){ |h,kv| k,v = kv ; h[k] = v ; h }
end
odbc::Database.new.drvconnect(driver)
else
odbc.connect config[:dsn], config[:username], config[:password]
end.tap do |c|
if c.respond_to?(:use_time)
c.use_time = true
c.use_utc = ActiveRecord::Base.default_timezone == :utc
Expand Down

4 comments on commit a99c5f9

@roelofb
Copy link

Choose a reason for hiding this comment

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

This will raise a NameError exception on line 359 - undefined local variable or method `dsn'.

That line should probably read:
driver.attrs = config[:dsn].split(';').map{ |atr| atr.split('=') }.reject{ |kv| kv.size != 2 }.inject({}){ |h,kv| k,v = kv ; h[k] = v ; h }

@metaskills
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah lovely :/
I'll fix that soon!

@Arie
Copy link

@Arie Arie commented on a99c5f9 Sep 21, 2010

Choose a reason for hiding this comment

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

Shouldn't it be d.attrs = instead of driver.attr = as well?

@ebryn
Copy link
Contributor

@ebryn ebryn commented on a99c5f9 Sep 21, 2010

Choose a reason for hiding this comment

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

It's been fixed. Thanks for pointing out the typos guys!

Please sign in to comment.