简体   繁体   中英

ActiveRecord SQL Server Adapter not saving changes in transaction

I'm using the Rails Gem activerecord-sqlserver-adapter to read from a MS SQL database. We are still on Rails 4.2.6 therefore we're using version 4.2.0 of the gem as well as tiny_tds.

Reads work fine from the database, however, writes are not having any effect.

In this example, I have an object that I'm updating a parameter on:

(byebug) VisualBase.transaction do visual_line.freight_note = 'test' 
end
"test"
(byebug) visual_line.freight_note = 'test'
"test"
(byebug) VisualBase.transaction do visual_line.save! end
true
(byebug) 

And here's the logs:

SQL (1.3ms)  BEGIN TRANSACTION
SQL (0.7ms)  COMMIT TRANSACTION
SQL (4.2ms)  BEGIN TRANSACTION
SQL (1.5ms)  COMMIT TRANSACTION

There's no actual write to the database? Normally I see a log of the SQL commands being executed when it's reading from the database, but I'm not even seeing this when it comes to writing to it. Has anyone else come across this before?

In response to one of the answers below, here's my latest attempt:

VisualBase.transaction do 
    visual_line = VisualCustomerOrderLine.where('cust_order_id' => 'CO-304560').order(:rowid).first
    visual_line.freight_note = 'test' 
    visual_line.save!
end

VisualCustomerOrderBinary Load (1.4ms)  EXEC sp_executesql N'SELECT  [CUST_ORDER_BINARY].* FROM [CUST_ORDER_BINARY] WHERE [CUST_ORDER_BINARY].[CUST_ORDER_ID] = @0  ORDER BY [CUST_ORDER_BINARY].[CUST_ORDER_ID] ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY', N'@0 nvarchar(max)', @0 = N'CO-304560'  [[nil, "CO-304560"]]
  VisualCustomerOrderLine Load (3.8ms)  EXEC sp_executesql N'SELECT [CUST_ORDER_LINE].* FROM [CUST_ORDER_LINE] WHERE [CUST_ORDER_LINE].[cust_order_id] = N''CO-304560'''
  SQL (0.9ms)  BEGIN TRANSACTION
  VisualCustomerOrderLine Load (3.5ms)  EXEC sp_executesql N'SELECT  [CUST_ORDER_LINE].* FROM [CUST_ORDER_LINE] WHERE [CUST_ORDER_LINE].[cust_order_id] = N''CO-304560''  ORDER BY [CUST_ORDER_LINE].[rowid] ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY'
  SQL (38.0ms)  COMMIT TRANSACTION

Unfortunately, when I checked the database, that value was still null. And looking at the log, I don't see a write attempt.

VisualBase.transaction do 
  visual_line = VisualLine.find(4711)
  visual_line.freight_note = 'test' 
  visual_line.save!
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM