Multiple types in statement now supported

This commit is contained in:
Karl Southern 2016-07-07 11:00:33 +01:00
parent 0f37792177
commit 43eb5d969d
5 changed files with 18 additions and 13 deletions

View File

@ -246,14 +246,15 @@ 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|
value = event.get(i) if i.is_a? String
value = event.get(i)
value = if value.nil? and i.to_s =~ /%{/ if value.nil? and i =~ /%\{/
event.sprintf(i) value = event.sprintf(i)
else end
value else
end value = i
end
case value case value
when Time when Time
# See LogStash::Timestamp, below, for the why behind strftime. # See LogStash::Timestamp, below, for the why behind strftime.

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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