Class: ActiveRecord::StatementCache::PartialQuery

Inherits:
Object
  • Object
show all
Defined in:
ext/active_record/statement_cache.rb

Instance Method Summary collapse

Constructor Details

#initialize(values, retryable: false, sunstone: false) ⇒ PartialQuery

TODO: drop this Rails 8.0 compatibility default when Rails 8.0 support is dropped, and make retryable: a required keyword again. retryable: is required on Rails 8.1 but absent from 8.0's caller.



13
14
15
16
17
18
19
20
21
22
# File 'ext/active_record/statement_cache.rb', line 13

def initialize(values, retryable: false, sunstone: false)
  @values = values
  @indexes = if sunstone
  else
    values.each_with_index.find_all { |thing, i|
      Substitute === thing
    }.map(&:last)
  end
  @retryable = retryable
end

Instance Method Details

#sql_for(binds, connection) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'ext/active_record/statement_cache.rb', line 24

def sql_for(binds, connection)
  if connection.is_a?(ActiveRecord::ConnectionAdapters::SunstoneAPIAdapter)
    @values
  else
    val = @values.dup
    @indexes.each do |i|
      value = binds.shift
      if ActiveModel::Attribute === value
        value = value.value_for_database
      end
      val[i] = connection.quote(value)
    end
    val.join
  end
end