Module: Db2Query::Logger

Included in:
Connection
Defined in:
lib/db2_query/logger.rb

Defined Under Namespace

Classes: StatementInvalid

Instance Method Summary collapse

Instance Method Details

#log(sql, binds = [], args = [], &block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/db2_query/logger.rb', line 15

def log(sql, binds = [], args = [], &block)
  instrument(
    "sql.active_record",
    sql:               sql,
    name:              "SQL",
    binds:             binds,
    type_casted_binds: args,
    statement_name:    nil,
    connection_id:     object_id,
    connection:        self) do
    mutex.synchronize do
      yield
    end
  rescue => e
    raise translate_exception_class(e, sql, binds)
  end
end

#translate_exception(exception, message:, sql:, binds:) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/db2_query/logger.rb', line 33

def translate_exception(exception, message:, sql:, binds:)
  case exception
  when RuntimeError
    exception
  else
    StatementInvalid.new(message, sql: sql, binds: binds)
  end
end

#translate_exception_class(e, sql, binds) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/db2_query/logger.rb', line 5

def translate_exception_class(e, sql, binds)
  message = "#{e.class.name}: #{e.message}"

  exception = translate_exception(
    e, message: message, sql: sql, binds: binds
  )
  exception.set_backtrace e.backtrace
  exception
end