Provisionally address issue 46

This commit is contained in:
Karl Southern 2016-07-07 08:50:58 +01:00
parent b5419813ba
commit 61c7a1307e

View File

@ -286,10 +286,18 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
def add_statement_event_params(statement, event)
@statement[1..-1].each_with_index do |i, idx|
case event[i]
value = event[i]
if value.nil? and i.to_s =~ /%{/
value = event.sprintf(i)
else
value = i
end
case value
when Time
# See LogStash::Timestamp, below, for the why behind strftime.
statement.setString(idx + 1, event[i].strftime(STRFTIME_FMT))
statement.setString(idx + 1, value.strftime(STRFTIME_FMT))
when LogStash::Timestamp
# XXX: Using setString as opposed to setTimestamp, because setTimestamp
# doesn't behave correctly in some drivers (Known: sqlite)
@ -298,38 +306,36 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
# choke on the 'T' in the string (Known: Derby).
#
# strftime appears to be the most reliable across drivers.
statement.setString(idx + 1, event[i].time.strftime(STRFTIME_FMT))
statement.setString(idx + 1, value.time.strftime(STRFTIME_FMT))
when Fixnum, Integer
statement.setInt(idx + 1, event[i])
statement.setInt(idx + 1, value)
when Float
statement.setFloat(idx + 1, event[i])
statement.setFloat(idx + 1, value)
when String
statement.setString(idx + 1, event[i])
when true
statement.setBoolean(idx + 1, true)
when false
statement.setBoolean(idx + 1, false)
else
if event[i].nil? and i =~ /%\{/
statement.setString(idx + 1, event.sprintf(i))
statement.setString(idx + 1, value)
when true, false
statement.setBoolean(idx + 1, value)
else
statement.setString(idx + 1, nil)
end
end
end
statement
end
def log_jdbc_exception(exception, retrying)
current_exception = exception
log_text = 'JDBC Exception. ' + (retrying ? 'Retrying' : 'No retry') + '.'
loop do
if retrying
@logger.error("JDBC Exception. Retrying.", :exception => current_exception)
else
@logger.error("JDBC Exception. No retry.", :exception => current_exception)
end
@logger.error(log_text, :exception => current_exception, :backtrace => current_exception.backtrace)
if current_exception.respond_to? 'getNextException'
current_exception = current_exception.getNextException()
else
current_exception = nil
end
break if current_exception == nil
end
end