Skip to content

Transaction rollback fails with "use_output_insert == false" if a SQL error happened during the transaction #390

@naag

Description

@naag

We're running a Rails 4.2.0 app with activerecord-sqlserver-adapter 4.2.2 and SQL Server 2012 and have run into an issue with both emoji encoding and transaction rollback in that scenario. Trying to create a simple record with an emoji fails due to TinyTDS character conversion, but the transaction rollback also fails when using ActiveRecord::ConnectionAdapters::SQLServerAdapter.use_output_inserted = false .

Example:

ActiveRecord::ConnectionAdapters::SQLServerAdapter.use_output_inserted = false
Emoji.create!(text: "😢")

This fails with these error messages:

Started GET "/encoding/really_bad" for 172.17.42.1 at 2015-02-16 15:37:49 +0000
Processing by EncodingController#really_bad as */*
  SQL (1.4ms)  BEGIN TRANSACTION
  SQL (0.3ms)  EXEC sp_executesql N'INSERT INTO [emojis] ([text]) VALUES (@0); SELECT CAST(SCOPE_IDENTITY() AS bigint) AS Ident', N'@0 nvarchar(4000)', @0 = N'😢'  [["text", "😢"]]
TinyTds::Error: Error converting characters into server's character set. Some character(s) could not be converted: EXEC sp_executesql N'INSERT INTO [emojis] ([text]) VALUES (@0); SELECT CAST(SCOPE_IDENTITY() AS bigint) AS Ident', N'@0 nvarchar(4000)', @0 = N'😢'
  SQL (3.3ms)  ROLLBACK TRANSACTION
TinyTds::Error: Unclosed quotation mark after the character string '@0 nvarcharROLLBACK TRANSACTION'.: ROLLBACK TRANSACTION
Completed 500 Internal Server Error in 31ms

ActiveRecord::StatementInvalid (TinyTds::Error: Unclosed quotation mark after the character string '@0 nvarcharROLLBACK TRANSACTION'.: ROLLBACK TRANSACTION)

but unfortunately we have some insert triggers on the database and thus cannot change the insert mode.

We've created a sample Rails application which shows this behaviour at https://github.com/naag/sqlserver-encoding. Just run it with rails s and curl http://127.0.0.1:3003/encoding/good, curl http://127.0.0.1:3003/encoding/bad, curl http://127.0.0.1:3003/encoding/really_bad. They demonstrate the three cases (no emoji, emoji with use_output_inserted = true and use_output_inserted = false).

Any help is really appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions