load_data_infile 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/load_data_infile.rb +11 -11
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/load_data_infile.rb
CHANGED
@@ -66,33 +66,33 @@ module LoadDataInfile
|
|
66
66
|
|
67
67
|
c.file_name = quote_value options[:path]
|
68
68
|
|
69
|
-
c.replace_or_ignore = options[:on_duplicates] if options[:on_duplicates]
|
69
|
+
c.replace_or_ignore = options[:on_duplicates] if [:REPLACE, :IGNORE].include?(options[:on_duplicates])
|
70
70
|
|
71
71
|
c.table_name = options[:table] ? "`#{ options[:table] }`" : quoted_table_name
|
72
72
|
|
73
|
-
c.charset = "CHARACTER SET #{
|
73
|
+
c.charset = "CHARACTER SET #{options[:charset]}" if options[:charset]
|
74
74
|
|
75
75
|
if options[:terminated_by] || options[:enclosed_by] || options[:optionally_enclosed_by] || options[:escaped_by]
|
76
76
|
c.fields_definitions = " FIELDS " # or COLUMNS
|
77
|
-
c.fields_definitions << " TERMINATED BY #{
|
78
|
-
c.fields_definitions << " ENCLOSED BY #{
|
79
|
-
c.fields_definitions << " OPTIONALLY ENCLOSED BY #{
|
80
|
-
c.fields_definitions << " ESCAPED BY #{
|
77
|
+
c.fields_definitions << " TERMINATED BY '#{ options[:terminated_by] }' " if options[:terminated_by]
|
78
|
+
c.fields_definitions << " ENCLOSED BY '#{ options[:enclosed_by] }' " if options[:enclosed_by]
|
79
|
+
c.fields_definitions << " OPTIONALLY ENCLOSED BY '#{ options[:optionally_enclosed_by] }' " if options[:optionally_enclosed_by]
|
80
|
+
c.fields_definitions << " ESCAPED BY '#{ options[:escaped_by] }' " if options[:escaped_by]
|
81
81
|
end
|
82
82
|
|
83
83
|
if options[:lines_terminated_by] || options[:lines_starting_by]
|
84
84
|
c.lines_defitions = " LINES "
|
85
|
-
c.lines_defitions << " STARTING BY #{
|
86
|
-
c.lines_defitions << " TERMINATED BY #{
|
85
|
+
c.lines_defitions << " STARTING BY '#{options[:lines_starting_by]}' " if options[:lines_starting_by]
|
86
|
+
c.lines_defitions << " TERMINATED BY '#{options[:lines_terminated_by]}' " if options[:lines_terminated_by]
|
87
87
|
end
|
88
88
|
|
89
|
-
c.ignores = "IGNORE #{options[:ignore]} LINES" if options[:ignore]
|
89
|
+
c.ignores = "IGNORE #{options[:ignore].to_i} LINES" if options[:ignore].to_i > 0
|
90
90
|
|
91
91
|
c.columns = " (#{options[:columns].join(", ")}) " if options[:columns]
|
92
92
|
|
93
93
|
if options[:mappings] && options[:mappings].length > 0
|
94
|
-
s = options[:mappings].map{|column, mapping| "#{column} = #{mapping}" }.join(",")
|
95
|
-
c.mappings = "SET #{s}"
|
94
|
+
s = options[:mappings].map{|column, mapping| "#{column} = #{mapping}" }.join(", ")
|
95
|
+
c.mappings = " SET #{s} "
|
96
96
|
end
|
97
97
|
|
98
98
|
disable_keys(c.table_name) if disable_keys_option
|