Class: LoadDataInfile2::Sql

Inherits:
Object
  • Object
show all
Defined in:
lib/load_data_infile2/sql.rb

Instance Method Summary collapse

Constructor Details

#initialize(file, table, options = {}) ⇒ Sql

Returns a new instance of Sql.

Parameters:

  • file (String)

    File name

  • table (String)

    Table name

  • options (Hash) (defaults to: {})

    Options for ‘LOAD DATA INFILE` query

Options Hash (options):

  • :low_priority_or_concurrent (Symbol)

    :low_priority or :concurrent option

  • :replace_or_ignore (Symbol)

    :replace or :ignore for duplicated record

  • :local_infile (Boolean)

    Use local file

  • :partition (Array)

    Partition names

  • :charset (String)

    Character set

  • :fields_terminated_by (String)

    Column delimiter

  • :fields_enclosed_by (String)

    Enclosure character, for example double quote

  • :fields_optionally_enclosed_by (String)

    If the input value is not necessarily enclosed, use OPTIONALLY

  • :fields_escaped_by (String)

    Escape character

  • :lines_starting_by (String)

    Common prefix for all lines to skip over the prefix, and anything before it

  • :lines_terminated_by (String)

    Line delimiter

  • :ignore_lines (String)

    Number of ignore lines from the start of the file

  • :columns (Array)

    Specify a column list, if the order of the fields in the input file differs from the order of the columns in the table The column list can contain either column names or user variables

  • :set (Hash)

    Key of Hash should have only column name, value of Hash can use a scalar subquery

See Also:



23
24
25
26
27
# File 'lib/load_data_infile2/sql.rb', line 23

def initialize(file, table, options = {})
  @file = file
  @table = table
  @options = options
end

Instance Method Details

#buildObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/load_data_infile2/sql.rb', line 29

def build
  [
    load_data_infile,
    replace_or_ignore,
    into_table,
    partition,
    character_set,
    fields,
    lines,
    ignore_lines,
    columns,
    set
  ].compact.join(' ').concat(';')
end