From 3a88a8fec126b338a619d66a3e8c282cd90cd94c Mon Sep 17 00:00:00 2001 From: Aidan Haran Date: Wed, 29 May 2024 11:21:35 +0100 Subject: [PATCH] Update sqlserver.rb --- lib/arel/visitors/sqlserver.rb | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/lib/arel/visitors/sqlserver.rb b/lib/arel/visitors/sqlserver.rb index 5ca0d01ac..bfab75b99 100644 --- a/lib/arel/visitors/sqlserver.rb +++ b/lib/arel/visitors/sqlserver.rb @@ -34,34 +34,31 @@ def visit_Arel_Nodes_UpdateStatement(o, collector) o.limit = Nodes::Limit.new(9_223_372_036_854_775_807) end + if o.key && o.key.size > 1 + collector.retryable = false + _visit_Arel_Nodes_UpdateStatement(o, collector) + else + super + end + end - - collector.retryable = false - # o = prepare_update_statement(o) - + def _visit_Arel_Nodes_UpdateStatement(o, collector) collector << "UPDATE " - - visit o.relation.left, collector + if has_join_sources?(o) + visit o.relation.left, collector + else + visit o.relation, collector + end collect_nodes_for o.values, collector, " SET " collector << " FROM " - visit o.relation.left, collector - - collector << " " - collector = visit o.relation.right, collector + visit o.relation, collector collect_nodes_for o.wheres, collector, " WHERE ", " AND " collect_nodes_for o.orders, collector, " ORDER BY " maybe_visit o.limit, collector - - - # - - - - # super end def visit_Arel_Nodes_Lock(o, collector)