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 16 16 :host => 'localhost', 17 17 :username => 'sa', 18 18 :database => 'activerecord_unittest2' 19 }, 20 'arunit_trusted' => { 21 :adapter => 'sqlserver', 22 :host => 'localhost', 23 :windows_auth => true, 24 :database => 'activerecord_unittest' 19 25 } 20 26 } 21 27 -
activerecord/test/adapter_test_sqlserver.rb
old new 19 19 def test_real_column_has_float_type 20 20 assert_equal :float, TableWithRealColumn.columns_hash["real_number"].type 21 21 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 22 36 23 37 # SQL Server 2000 has a bug where some unambiguous date formats are not 24 38 # correctly identified if the session language is set to german -
activerecord/test/abstract_unit.rb
old new 63 63 ActiveRecord::Base.connection.class.class_eval do 64 64 65 65 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\(\)/] 67 67 68 68 def execute_with_counting(sql, name = nil, &block) 69 69 $query_count ||= 0 -
activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb
old new 32 32 mode = config[:mode] ? config[:mode].to_s.upcase : 'ADO' 33 33 username = config[:username] ? config[:username].to_s : 'sa' 34 34 password = config[:password] ? config[:password].to_s : '' 35 auth = config[:windows_auth] ? 'Integrated Security=SSPI' : "User ID=#{username};Password=#{password}" 35 36 autocommit = config.key?(:autocommit) ? config[:autocommit] : true 36 37 if mode == "ODBC" 37 38 raise ArgumentError, "Missing DSN. Argument ':dsn' must be set in order for this adapter to work." unless config.has_key?(:dsn) … … 41 42 raise ArgumentError, "Missing Database. Argument ':database' must be set in order for this adapter to work." unless config.has_key?(:database) 42 43 database = config[:database] 43 44 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};" 45 46 end 46 47 conn = DBI.connect(driver_url, username, password) 47 48 conn["AutoCommit"] = autocommit … … 296 297 end 297 298 298 299 def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) 300 # TODO: use @@IDENTITY when connecting to legacy databases 299 301 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"] 301 303 end 302 304 303 305 def update(sql, name = nil) … … 431 433 end 432 434 433 435 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 443 451 end 444 452 end 445 453 end 446 454 end 447 indexes448 455 ensure 449 ActiveRecord::Base.connection.instance_variable_get("@connection")["AutoCommit"] = true456 @connection["AutoCommit"] = true if original_autocommit 450 457 end 451 458 452 459 def rename_table(name, new_name)