Multiple types in statement now supported
This commit is contained in:
parent
0f37792177
commit
43eb5d969d
|
@ -246,13 +246,14 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
|
|||
|
||||
def add_statement_event_params(statement, event)
|
||||
@statement[1..-1].each_with_index do |i, idx|
|
||||
value = event.get(i)
|
||||
|
||||
value = if value.nil? and i.to_s =~ /%{/
|
||||
event.sprintf(i)
|
||||
else
|
||||
value
|
||||
end
|
||||
if i.is_a? String
|
||||
value = event.get(i)
|
||||
if value.nil? and i =~ /%\{/
|
||||
value = event.sprintf(i)
|
||||
end
|
||||
else
|
||||
value = i
|
||||
end
|
||||
|
||||
case value
|
||||
when Time
|
||||
|
|
|
@ -31,7 +31,11 @@ RSpec.shared_context 'when outputting messages' do
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
let(:systemd_database_service) do
|
||||
|
|
|
@ -10,7 +10,7 @@ describe 'logstash-output-jdbc: derby', if: ENV['JDBC_DERBY_JAR'] do
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
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',
|
||||
'connection_string' => 'jdbc:derby:memory:testdb;create=true',
|
||||
'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
|
||||
}
|
||||
end
|
||||
|
|
|
@ -18,7 +18,7 @@ describe 'logstash-output-jdbc: mysql', if: ENV['JDBC_MYSQL_JAR'] do
|
|||
'driver_class' => 'com.mysql.jdbc.Driver',
|
||||
'connection_string' => 'jdbc:mysql://localhost/logstash_output_jdbc_test?user=root',
|
||||
'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
|
||||
}
|
||||
end
|
||||
|
|
|
@ -20,7 +20,7 @@ describe 'logstash-output-jdbc: sqlite', if: ENV['JDBC_SQLITE_JAR'] do
|
|||
'driver_class' => 'org.sqlite.JDBC',
|
||||
'connection_string' => "jdbc:sqlite:#{JDBC_SQLITE_FILE}",
|
||||
'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
|
||||
}
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user