Multiple types in statement now supported
This commit is contained in:
parent
0f37792177
commit
43eb5d969d
|
@ -246,12 +246,13 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
|
||||||
|
|
||||||
def add_statement_event_params(statement, event)
|
def add_statement_event_params(statement, event)
|
||||||
@statement[1..-1].each_with_index do |i, idx|
|
@statement[1..-1].each_with_index do |i, idx|
|
||||||
|
if i.is_a? String
|
||||||
value = event.get(i)
|
value = event.get(i)
|
||||||
|
if value.nil? and i =~ /%\{/
|
||||||
value = if value.nil? and i.to_s =~ /%{/
|
value = event.sprintf(i)
|
||||||
event.sprintf(i)
|
end
|
||||||
else
|
else
|
||||||
value
|
value = i
|
||||||
end
|
end
|
||||||
|
|
||||||
case value
|
case value
|
||||||
|
|
|
@ -31,7 +31,11 @@ RSpec.shared_context 'when outputting messages' do
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:jdbc_create_table) do
|
let(:jdbc_create_table) do
|
||||||
"CREATE table #{jdbc_test_table} (created_at datetime not null, message varchar(512) not null)"
|
"CREATE table #{jdbc_test_table} (created_at datetime not null, message varchar(512) not null, message_sprintf varchar(512) not null, static_int int not null, static_bit bit not null)"
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:jdbc_statement) do
|
||||||
|
["insert into #{jdbc_test_table} (created_at, message, message_sprintf, static_int, static_bit) values(?, ?, ?, ?, ?)", '@timestamp', 'message', 'sprintf-%{message}', 1, true]
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:systemd_database_service) do
|
let(:systemd_database_service) do
|
||||||
|
|
|
@ -10,7 +10,7 @@ describe 'logstash-output-jdbc: derby', if: ENV['JDBC_DERBY_JAR'] do
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:jdbc_create_table) do
|
let(:jdbc_create_table) do
|
||||||
"CREATE table #{jdbc_test_table} (created_at timestamp not null, message varchar(512) not null)"
|
"CREATE table #{jdbc_test_table} (created_at timestamp not null, message varchar(512) not null, message_sprintf varchar(512) not null, static_int int not null, static_bit boolean not null)"
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:jdbc_settings) do
|
let(:jdbc_settings) do
|
||||||
|
@ -18,7 +18,7 @@ describe 'logstash-output-jdbc: derby', if: ENV['JDBC_DERBY_JAR'] do
|
||||||
'driver_class' => 'org.apache.derby.jdbc.EmbeddedDriver',
|
'driver_class' => 'org.apache.derby.jdbc.EmbeddedDriver',
|
||||||
'connection_string' => 'jdbc:derby:memory:testdb;create=true',
|
'connection_string' => 'jdbc:derby:memory:testdb;create=true',
|
||||||
'driver_jar_path' => ENV[jdbc_jar_env],
|
'driver_jar_path' => ENV[jdbc_jar_env],
|
||||||
'statement' => ['insert into logstash_output_jdbc_test (created_at, message) values(?, ?)', '@timestamp', 'message'],
|
'statement' => jdbc_statement,
|
||||||
'max_flush_exceptions' => 1
|
'max_flush_exceptions' => 1
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,7 +18,7 @@ describe 'logstash-output-jdbc: mysql', if: ENV['JDBC_MYSQL_JAR'] do
|
||||||
'driver_class' => 'com.mysql.jdbc.Driver',
|
'driver_class' => 'com.mysql.jdbc.Driver',
|
||||||
'connection_string' => 'jdbc:mysql://localhost/logstash_output_jdbc_test?user=root',
|
'connection_string' => 'jdbc:mysql://localhost/logstash_output_jdbc_test?user=root',
|
||||||
'driver_jar_path' => ENV[jdbc_jar_env],
|
'driver_jar_path' => ENV[jdbc_jar_env],
|
||||||
'statement' => ["insert into #{jdbc_test_table} (created_at, message) values(?, ?)", '@timestamp', 'message'],
|
'statement' => jdbc_statement,
|
||||||
'max_flush_exceptions' => 1
|
'max_flush_exceptions' => 1
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,7 +20,7 @@ describe 'logstash-output-jdbc: sqlite', if: ENV['JDBC_SQLITE_JAR'] do
|
||||||
'driver_class' => 'org.sqlite.JDBC',
|
'driver_class' => 'org.sqlite.JDBC',
|
||||||
'connection_string' => "jdbc:sqlite:#{JDBC_SQLITE_FILE}",
|
'connection_string' => "jdbc:sqlite:#{JDBC_SQLITE_FILE}",
|
||||||
'driver_jar_path' => ENV[jdbc_jar_env],
|
'driver_jar_path' => ENV[jdbc_jar_env],
|
||||||
'statement' => ["insert into #{jdbc_test_table} (created_at, message) values(?, ?)", '@timestamp', 'message'],
|
'statement' => jdbc_statement,
|
||||||
'max_flush_exceptions' => 1
|
'max_flush_exceptions' => 1
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user