lib/fluent/plugin/out_mysql_bulk.rb in fluent-plugin-mysql-bulk-0.0.7 vs lib/fluent/plugin/out_mysql_bulk.rb in fluent-plugin-mysql-bulk-0.0.8
- old
+ new
@@ -37,11 +37,11 @@
@on_duplicate_update_keys = @on_duplicate_update_keys.split(',')
@on_duplicate_key_update_sql = ' ON DUPLICATE KEY UPDATE '
updates = []
@on_duplicate_update_keys.each do |update_column|
- updates.push(" #{update_column} = VALUES(#{update_column})")
+ updates << "#{update_column} = VALUES(#{update_column})"
end
@on_duplicate_key_update_sql += updates.join(',')
end
@column_names = @column_names.split(',')
@@ -83,20 +83,19 @@
)
end
def write(chunk)
@handler = client
- values_templates = []
values = []
+ values_template = "(#{ @column_names.map { |key| '?' }.join(',') })"
chunk.msgpack_each do |tag, time, data|
- values_templates << "(#{ @column_names.map { |key| '?' }.join(',') })"
- values.concat(data)
+ values << Mysql2::Client.pseudo_bind(values_template, data)
end
- sql = "INSERT INTO #{@table} (#{@column_names.join(',')}) VALUES #{values_templates.join(',')}"
+ sql = "INSERT INTO #{@table} (#{@column_names.join(',')}) VALUES #{values.join(',')}"
sql += @on_duplicate_key_update_sql if @on_duplicate_key_update
- $log.info "bulk insert values size => #{values_templates.size}"
- @handler.xquery(sql, values)
+ $log.info "bulk insert values size => #{values.size}"
+ @handler.xquery(sql)
@handler.close
end
private