Sha256: 3e440132dc47c8018f587c5020c0877d1cc193bfd14ed60d841a48c5c0482537

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

# Source code for the MysqlAdapter extensions.
module ActiveRecord #:nodoc:
  module ConnectionAdapters #:nodoc:
    # Adds new functionality to ActiveRecord MysqlAdapter.
    class MysqlAdapter < AbstractAdapter
      # Bulk load the data in the specified file. This implementation always uses the LOCAL keyword
      # so the file must be found locally, not on the remote server, to be loaded.
      #
      # Options:
      # * <tt>:ignore</tt> -- Ignore the specified number of lines from the source file
      # * <tt>:columns</tt> -- Array of column names defining the source file column order
      # * <tt>:fields</tt> -- Hash of options for fields:
      #   * <tt>:delimited_by</tt> -- The field delimiter
      #   * <tt>:enclosed_by</tt> -- The field enclosure
      def bulk_load(file, table_name, options={})
        q = "LOAD DATA LOCAL INFILE '#{file}' INTO TABLE #{table_name}"
        if options[:fields]
          q << " FIELDS"
          q << " TERMINATED BY '#{options[:fields][:delimited_by]}'" if options[:fields][:delimited_by]
          q << " ENCLOSED BY '#{options[:fields][:enclosed_by]}'" if options[:fields][:enclosed_by]
        end
        q << " IGNORE #{options[:ignore]} LINES" if options[:ignore]
        q << " (#{options[:columns].join(',')})" if options[:columns]
        execute(q)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
adapter_extensions-0.1.0 lib/active_record/connection_adapters/mysql_adapter.rb
adapter_extensions-0.1.1 lib/adapter_extensions/connection_adapters/mysql_adapter.rb