Skip to content

Commit eee322a

Browse files
committed
Make rollback transaction transcount aware for implicit error rollbacks. Fixes #390
1 parent 8c492a0 commit eee322a

File tree

6 files changed

+19
-1
lines changed

6 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## v4.2.3
22

33
* Fix SET defaults when using Azure.
4+
* Test insert 4-byte unicode chars.
5+
* Make rollback transaction transcount aware for implicit error rollbacks. Fixes #390
46

57

68
## v4.2.2

lib/active_record/connection_adapters/sqlserver/database_statements.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def commit_db_transaction
6666
end
6767

6868
def rollback_db_transaction
69-
do_execute 'ROLLBACK TRANSACTION'
69+
do_execute 'IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION'
7070
end
7171

7272
include Savepoints

test/cases/helper_sqlserver.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ def connection
3333
ActiveRecord::Base.connection
3434
end
3535

36+
def with_use_output_inserted_disabled
37+
ActiveRecord::ConnectionAdapters::SQLServerAdapter.use_output_inserted = false
38+
yield
39+
ensure
40+
ActiveRecord::ConnectionAdapters::SQLServerAdapter.use_output_inserted = true
41+
end
42+
3643
end
3744
end
3845

test/cases/transaction_test_sqlserver.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# encoding: UTF-8
12
require 'cases/helper_sqlserver'
23
require 'models/ship'
34
require 'models/developer'

test/cases/uuid_test_sqlserver.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# encoding: UTF-8
12
require 'cases/helper_sqlserver'
23

34
class SQLServerUuidTest < ActiveRecord::TestCase
@@ -10,6 +11,7 @@ class SQLServerUuidTest < ActiveRecord::TestCase
1011
end
1112

1213
it 'can create with a new pk' do
14+
# Type::Uuid::ACCEPTABLE_UUID
1315
obj = SSTestUuid.create!
1416
obj.id.must_be :present?
1517
obj.id.must_match acceptable_uuid
@@ -38,4 +40,9 @@ class SQLServerUuidTest < ActiveRecord::TestCase
3840
column.default_function.must_equal "newid()"
3941
end
4042

43+
it 'can insert even when use_output_inserted to false ' do
44+
obj = with_use_output_inserted_disabled { SSTestUuid.create!(name: "😢") }
45+
obj.id.must_be :nil?
46+
end
47+
4148
end

test/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ default_connection_info: &default_connection_info
1010
password: <%= ENV['ACTIVERECORD_UNITTEST_PASS'] || '' %>
1111
azure: <%= !ENV['ACTIVERECORD_UNITTEST_AZURE'].nil? %>
1212
collation: <%= ENV['ACTIVERECORD_UNITTEST_COLLATION'] || nil %>
13+
encoding: utf8
1314

1415
connections:
1516

0 commit comments

Comments
 (0)