Skip to content

Commit 87fd749

Browse files
authored
Reintroduce visit_Arel_Nodes_HomogeneousIn monkey-patch (#1137)
1 parent 9dc8d7a commit 87fd749

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lib/active_record/tasks/sqlserver_database_tasks.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def purge
5353
end
5454

5555
def clear_active_connections!
56-
ActiveRecord::Base.connection_handler.clear_active_connections!
56+
ActiveRecord::Base.connection_handler.clear_active_connections!(:all)
5757
end
5858

5959
def structure_dump(filename, extra_flags)

lib/arel/visitors/sqlserver.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,38 @@ def visit_Arel_Nodes_Grouping(o, collector)
6464
super
6565
end
6666

67+
def visit_Arel_Nodes_HomogeneousIn(o, collector)
68+
collector.preparable = false
69+
70+
visit o.left, collector
71+
72+
if o.type == :in
73+
collector << " IN ("
74+
else
75+
collector << " NOT IN ("
76+
end
77+
78+
values = o.casted_values
79+
80+
# Monkey-patch start.
81+
column_name = o.attribute.name
82+
column_type = o.attribute.relation.type_for_attribute(column_name)
83+
column_type = column_type.cast_type if column_type.is_a?(ActiveRecord::Encryption::EncryptedAttributeType) # Use cast_type on encrypted attributes. Don't encrypt them again
84+
85+
if values.empty?
86+
collector << @connection.quote(nil)
87+
elsif @connection.prepared_statements && !column_type.serialized?
88+
# Add query attribute bindings rather than just values.
89+
attrs = values.map { |value| ActiveRecord::Relation::QueryAttribute.new(column_name, value, column_type) }
90+
collector.add_binds(attrs, &bind_block)
91+
else
92+
collector.add_binds(values, o.proc_for_binds, &bind_block)
93+
end
94+
# Monkey-patch end.
95+
96+
collector << ")"
97+
end
98+
6799
def visit_Arel_Nodes_SelectStatement(o, collector)
68100
@select_statement = o
69101
distinct_One_As_One_Is_So_Not_Fetch o

0 commit comments

Comments
 (0)