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

Ticket #8862: sqlserver_combined_minor_patches.diff

File sqlserver_combined_minor_patches.diff, 5.8 kB (added by tomafro, 2 years ago)
  • 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  
    1919  def test_real_column_has_float_type 
    2020    assert_equal :float, TableWithRealColumn.columns_hash["real_number"].type 
    2121  end 
     22   
     23  if ActiveRecord::Base.configurations['arunit_trusted'] 
     24    def test_trusted_connection 
     25      # open trusted connection 
     26      ActiveRecord::Base.establish_connection 'arunit_trusted' 
     27      @connection = ActiveRecord::Base.connection     
     28      assert_equal true, @connection.active? 
     29      # restore old connection 
     30    ensure 
     31      ActiveRecord::Base.establish_connection 'arunit' 
     32      @connection = ActiveRecord::Base.connection 
     33      assert_equal true, @connection.active? 
     34    end 
     35  end 
    2236 
    2337  # SQL Server 2000 has a bug where some unambiguous date formats are not  
    2438  # correctly identified if the session language is set to german 
  • activerecord/test/abstract_unit.rb

    old new  
    6363ActiveRecord::Base.connection.class.class_eval do   
    6464   
    6565  if not (const_get('IGNORED_SQL') rescue nil)     
    66     IGNORED_SQL = [/^PRAGMA/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/
     66    IGNORED_SQL = [/^PRAGMA/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT SCOPE_IDENTITY\(\)/
    6767 
    6868    def execute_with_counting(sql, name = nil, &block) 
    6969      $query_count ||= 0 
  • 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 
     
    296297      end 
    297298 
    298299      def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) 
     300        # TODO: use @@IDENTITY when connecting to legacy databases  
    299301        execute(sql, name) 
    300         id_value || select_one("SELECT @@IDENTITY AS Ident")["Ident"] 
     302        id_value || select_one("SELECT SCOPE_IDENTITY() AS scope_identity")["scope_identity"] 
    301303      end 
    302304 
    303305      def update(sql, name = nil) 
     
    431433      end 
    432434 
    433435      def indexes(table_name, name = nil) 
    434         ActiveRecord::Base.connection.instance_variable_get("@connection")["AutoCommit"] = false 
    435         indexes = []         
    436         execute("EXEC sp_helpindex '#{table_name}'", name) do |handle| 
    437           if handle.column_info.any? 
    438             handle.each do |index|  
    439               unique = index[1] =~ /unique/ 
    440               primary = index[1] =~ /primary key/ 
    441               if !primary 
    442                 indexes << IndexDefinition.new(table_name, index[0], unique, index[2].split(", ").map {|e| e.gsub('(-)','')}) 
     436        # TODO: Does SQL Server 2005 have information_schema.indexes?  If so, use that 
     437        # for 2005 adapter 
     438         
     439        original_autocommit = @connection["AutoCommit"] 
     440        @connection["AutoCommit"] = false if original_autocommit 
     441         
     442        returning(result = []) do 
     443          execute("EXEC sp_helpindex '#{table_name}'", name) do |handle| 
     444            if handle.column_info.any? 
     445              handle.each do |index|  
     446                unique = index[1] =~ /unique/ 
     447                primary = index[1] =~ /primary key/ 
     448                if !primary 
     449                  result << IndexDefinition.new(table_name, index[0], unique, index[2].split(", ").map {|e| e.gsub('(-)','')}) 
     450                end 
    443451              end 
    444452            end 
    445453          end 
    446454        end 
    447         indexes 
    448455      ensure 
    449         ActiveRecord::Base.connection.instance_variable_get("@connection")["AutoCommit"] = true 
     456        @connection["AutoCommit"] = true if original_autocommit 
    450457      end 
    451458             
    452459      def rename_table(name, new_name)