Method: ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::DatabaseStatements#exec_query

Defined in:
lib/active_record/connection_adapters/postgresql/database_statements.rb

#exec_query(sql, name = 'SQL', binds = []) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/active_record/connection_adapters/postgresql/database_statements.rb', line 136

def exec_query(sql, name = 'SQL', binds = [])
  log(sql, name, binds) do
    result = without_prepared_statement?(binds) ? exec_no_cache(sql, binds) :
                                                  exec_cache(sql, binds)

    types = {}
    fields = result.fields
    fields.each_with_index do |fname, i|
      ftype = result.ftype i
      fmod  = result.fmod i
      types[fname] = OID::TYPE_MAP.fetch(ftype, fmod) { |oid, mod|
        warn "unknown OID: #{fname}(#{oid}) (#{sql})"
        OID::Identity.new
      }
    end

    ret = ActiveRecord::Result.new(fields, result.values, types)
    result.clear
    return ret
  end
end