Method: ActiveRecord::ConnectionAdapters::OracleEnhanced::OCIConnection#select

Defined in:
lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb

#select(sql, name = nil, return_column_names = false) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb', line 190

def select(sql, name = nil, return_column_names = false)
  cursor = @raw_connection.exec(sql)
  cols = []
  # Ignore raw_rnum_ which is used to simulate LIMIT and OFFSET
  cursor.get_col_names.each do |col_name|
    col_name = _oracle_downcase(col_name)
    cols << col_name unless col_name == "raw_rnum_"
  end
  # Reuse the same hash for all rows
  column_hash = {}
  cols.each { |c| column_hash[c] = nil }
  rows = []
  get_lob_value = !(name == "Writable Large Object")

  while row = cursor.fetch
    hash = column_hash.dup

    cols.each_with_index do |col, i|
      col_value = typecast_result_value(row[i], get_lob_value)
       = cursor..fetch(i)
      if !.nil?
        key = .data_type
        case key.to_s.downcase
        when "char"
          col_value = col_value.to_s.rstrip
        end
      end
      hash[col] = col_value
    end

    rows << hash
  end

  return_column_names ? [rows, cols] : rows
ensure
  cursor.close if cursor
end