Class: ActiveRecord::Base
- Inherits:
-
Object
- Object
- ActiveRecord::Base
- Defined in:
- lib/activerecord-sqlserver-adapter/adonet_patch.rb
Class Method Summary collapse
Class Method Details
.sqlserver_connection(config) ⇒ Object
:nodoc:
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/activerecord-sqlserver-adapter/adonet_patch.rb', line 4 def self.sqlserver_connection(config) #:nodoc: config.symbolize_keys! mode = config[:mode] ? config[:mode].to_s.upcase : 'ADO' username = config[:username] ? config[:username].to_s : 'sa' password = config[:password] ? config[:password].to_s : '' database = config[:database] host = config[:host] ? config[:host].to_s : 'localhost' integrated_security = config[:integrated_security] if mode == "ODBC" raise ArgumentError, "Missing DSN. Argument ':dsn' must be set in order for this adapter to work." unless config.has_key?(:dsn) dsn = config[:dsn] driver_url = "DBI:ODBC:#{dsn}" = [driver_url, username, password] elsif mode == "ADO" raise ArgumentError, "Missing Database. Argument ':database' must be set in order for this adapter to work." unless config.has_key?(:database) if integrated_security = ["DBI:ADO:Provider=SQLOLEDB;Data Source=#{host};Initial Catalog=#{database};Integrated Security=SSPI"] else driver_url = "DBI:ADO:Provider=SQLOLEDB;Data Source=#{host};Initial Catalog=#{database};User ID=#{username};Password=#{password};" = [driver_url, username, password] end elsif mode == "ADONET" raise ArgumentError, "Missing Database. Argument ':database' must be set in order for this adapter to work." unless config.has_key?(:database) if integrated_security = ["DBI:MSSQL:server=#{host};initial catalog=#{database};integrated security=true"] else = ["DBI:MSSQL:server=#{host};initial catalog=#{database};user id=#{username};password=#{password}"] end else raise "Unknown mode #{mode}" end ConnectionAdapters::SQLServerAdapter.new(logger, ) end |