Class: BulkInsertActiveRecord::Inserters::Oracle

Inherits:
Base
  • Object
show all
Defined in:
lib/inserters/oracle.rb

Overview

Implementation specific for Oracle

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from BulkInsertActiveRecord::Inserters::Base

Instance Method Details

#execute(records, column_names) ⇒ Object

override



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/inserters/oracle.rb', line 5

def execute(records, column_names) # override
  statement = 'BEGIN INSERT INTO %{table_name}(%{columns_clause}) (%{values_clause}); END;'
  @connection.execute(format(statement, table_name: @quoted_table_name,
                                        columns_clause: column_names.map do |column_name|
                                          @connection.quote_column_name(column_name)
                                        end.join(','),
                                        values_clause: records.map do |record|
                                          value_clause = record.map { |value| @connection.quote(value) }.join(',')
                                          "SELECT #{value_clause} FROM dual"
                                        end.join(' UNION ')))
end