Skip to content

Commit

Permalink
Set bulk load option for MySQL automatically
Browse files Browse the repository at this point in the history
Previously, ActiveRecord had to be patched manually to make the bulk load optionwork correct - now it happens within AdapterExtensions itself
  • Loading branch information
darinwilson committed Nov 12, 2008
1 parent b4d9f42 commit ffb8e3a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 12 additions & 0 deletions lib/adapter_extensions/connection_adapters/mysql_adapter.rb
Expand Up @@ -35,6 +35,18 @@ def copy_table(old_table_name, new_table_name)
# * <tt>:enclosed_by</tt> -- The field enclosure
def do_bulk_load(file, table_name, options={})
return if File.size(file) == 0

# an unfortunate hack - setting the bulk load option after the connection has been
# established does not seem to have any effect, and since the connection is made when
# active-record is loaded, there's no chance for us to sneak it in earlier. So we
# disconnect, set the option, then reconnect - fortunately, this only needs to happen once.
unless @bulk_load_enabled
disconnect!
@connection.options(Mysql::OPT_LOCAL_INFILE, true)
connect
@bulk_load_enabled = true
end

q = "LOAD DATA LOCAL INFILE '#{file}' INTO TABLE #{table_name}"
if options[:fields]
q << " FIELDS"
Expand Down
12 changes: 0 additions & 12 deletions mysql_adapter_opt_local_infile.patch

This file was deleted.

0 comments on commit ffb8e3a

Please sign in to comment.