aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb
blob: f158946c6d5155d66f42598245cd8a7636396b91 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# frozen_string_literal: true

module ActiveRecord
  module ConnectionAdapters
    module DetermineIfPreparableVisitor
      attr_reader :preparable

      def accept(*)
        @preparable = true
        super
      end

      def visit_Arel_Nodes_In(o, collector)
        @preparable = false

        if Array === o.right && !o.right.empty?
          o.right.delete_if do |bind|
            if Arel::Nodes::BindParam === bind && Relation::QueryAttribute === bind.value
              !bind.value.boundable?
            end
          end
        end

        super
      end

      def visit_Arel_Nodes_SqlLiteral(*)
        @preparable = false
        super
      end
    end
  end
end