lib/kpm/database.rb in kpm-0.7.1 vs lib/kpm/database.rb in kpm-0.7.2
- old
+ new
@@ -100,10 +100,19 @@
if !table[:rows].nil? && table[:rows].size > 0
columns_names = table[:col_names].join(",").gsub(/'/,'')
rows = []
table[:rows].each do |row|
- rows << row.map{|value| value.is_a?(Symbol) ? value.to_s : "'#{value.to_s.gsub(/['"]/, "'" => "\\'", '"' => '\\"')}'" }.join(",")
+ rows << row.map do |value|
+ if value.is_a?(Symbol)
+ value.to_s
+ else
+ escaped_value = value.to_s.gsub(/['"]/, "'" => "\\'", '"' => '\\"')
+ .gsub('\N{LINE FEED}', "\n")
+ .gsub('\N{VERTICAL LINE}', "|")
+ "'#{escaped_value}'"
+ end
+ end.join(",")
end
value_data = rows.map{|row| "(#{row})" }.join(",")
statements << {:query => get_insert_statement(table_name,columns_names,value_data, rows.size),
\ No newline at end of file