简体   繁体   English

ActiveRecord SQL Server适配器未保存事务中的更改

[英]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. 我正在使用Rails Gem activerecord-sqlserver-adapter从MS SQL数据库读取。 We are still on Rails 4.2.6 therefore we're using version 4.2.0 of the gem as well as tiny_tds. 我们仍然在Rails 4.2.6上,因此我们在使用4.2.0版本的gem以及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. 通常,当从数据库中读取SQL命令时,会看到正在执行的SQL命令的日志,但是在写入数据库时​​,甚至看不到它。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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