Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #6580: sqlserver_adapter_trusted_connection.patch

File sqlserver_adapter_trusted_connection.patch, 3.8 kB (added by catan512, 2 years ago)

Updated patch with unittest

  • activerecord/test/connections/native_sqlserver/connection.rb

    old new  
    1616    :host     => 'localhost', 
    1717    :username => 'sa', 
    1818    :database => 'activerecord_unittest2' 
     19  }, 
     20  'arunit_trusted' => { 
     21    :adapter  => 'sqlserver', 
     22    :host     => 'localhost', 
     23    :windows_auth => true, 
     24    :database => 'activerecord_unittest' 
    1925  } 
    2026} 
    2127 
  • activerecord/test/adapter_test_sqlserver.rb

    old new  
    1414    @connection.execute("SET LANGUAGE us_english") 
    1515  end 
    1616 
     17  def test_trusted_connection 
     18    # open trusted connection 
     19    ActiveRecord::Base.establish_connection 'arunit_trusted' 
     20    @connection = ActiveRecord::Base.connection     
     21    assert_equal true, @connection.active? 
     22    # restore old connection 
     23    ActiveRecord::Base.establish_connection 'arunit' 
     24    @connection = ActiveRecord::Base.connection 
     25    assert_equal true, @connection.active? 
     26  end 
     27 
    1728  # SQL Server 2000 has a bug where some unambiguous date formats are not  
    1829  # correctly identified if the session language is set to german 
    1930  def test_date_insertion_when_language_is_german 
  • activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb

    old new  
    3232      mode        = config[:mode] ? config[:mode].to_s.upcase : 'ADO' 
    3333      username    = config[:username] ? config[:username].to_s : 'sa' 
    3434      password    = config[:password] ? config[:password].to_s : '' 
     35      auth        = config[:windows_auth] ? 'Integrated Security=SSPI' : "User ID=#{username};Password=#{password}" 
    3536      autocommit  = config.key?(:autocommit) ? config[:autocommit] : true 
    3637      if mode == "ODBC" 
    3738        raise ArgumentError, "Missing DSN. Argument ':dsn' must be set in order for this adapter to work." unless config.has_key?(:dsn) 
     
    4142        raise ArgumentError, "Missing Database. Argument ':database' must be set in order for this adapter to work." unless config.has_key?(:database) 
    4243        database  = config[:database] 
    4344        host      = config[:host] ? config[:host].to_s : 'localhost' 
    44         driver_url = "DBI:ADO:Provider=SQLOLEDB;Data Source=#{host};Initial Catalog=#{database};User Id=#{username};Password=#{password};" 
     45        driver_url = "DBI:ADO:Provider=SQLOLEDB;Data Source=#{host};Initial Catalog=#{database};#{auth};" 
    4546      end 
    4647      conn      = DBI.connect(driver_url, username, password) 
    4748      conn["AutoCommit"] = autocommit 
     
    167168    # 
    168169    # * <tt>:mode</tt>      -- ADO or ODBC. Defaults to ADO. 
    169170    # * <tt>:username</tt>  -- Defaults to sa. 
    170     # * <tt>:password</tt>  -- Defaults to empty string. 
     171    # * <tt>:password</tt>  -- Defaults to empty string. 
     172    # * <tt>:windows_auth</tt> -- Defaults to "User ID=#{username};Password=#{password}" 
    171173    # 
    172174    # ADO specific options: 
    173175    # 
    174176    # * <tt>:host</tt>      -- Defaults to localhost. 
    175     # * <tt>:database</tt>  -- The name of the database. No default, must be provided. 
     177    # * <tt>:database</tt>  -- The name of the database. No default, must be provided. 
     178    # * <tt>:windows_auth</tt> -- Use windows authentication instead of username/password. 
    176179    # 
    177180    # ODBC specific options:                    
    178181    #