Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/connection_adapters/sqlserver_adapter.rb

Class Method Summary collapse

Class Method Details

.sqlserver_connection(config) ⇒ Object

:nodoc:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 21

def self.sqlserver_connection(config) #:nodoc:
  config = config.symbolize_keys
  config.reverse_merge! :mode => :dblib, :host => 'localhost', :username => 'sa', :password => ''
  mode = config[:mode].to_s.downcase.underscore.to_sym
  case mode
  when :dblib
    require 'tiny_tds'
    warn("TinyTds v0.4.3 or higher required. Using #{TinyTds::VERSION}") unless TinyTds::Client.instance_methods.map(&:to_s).include?("active?")
  when :odbc
    raise ArgumentError, 'Missing :dsn configuration.' unless config.has_key?(:dsn)
    require 'odbc'
    require 'active_record/connection_adapters/sqlserver/core_ext/odbc'
  else
    raise ArgumentError, "Unknown connection mode in #{config.inspect}."
  end
  ConnectionAdapters::SQLServerAdapter.new(nil, logger, nil, config.merge(:mode=>mode))
end