Class: RDO::Statement

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/rdo/statement.rb

Overview

Represents a prepared statement.

This class actually just wraps a StatementExecutor, which only needs to conform to a duck-type

Instance Method Summary collapse

Constructor Details

#initialize(executor, logger) ⇒ Statement

Initialize a new Statement wrapping the given StatementExecutor.

Parameters:

  • executor (Object)

    any object that responds to #execute, #connection and #command



24
25
26
27
# File 'lib/rdo/statement.rb', line 24

def initialize(executor, logger)
  @executor = executor
  @logger   = logger
end

Instance Method Details

#execute(*bind_values) ⇒ Object

Execute the command using the given bind values.

Parameters:

  • args (Object...)

    bind parameters to use in place of ‘?’



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rdo/statement.rb', line 33

def execute(*bind_values)
  t = Time.now
  @executor.execute(*bind_values).tap do |rs|
    rs.info[:execution_time] ||= Time.now - t
    if logger.debug?
      logger.debug(
        "(%.6f) %s %s" % [
          rs.execution_time,
          command,
          ("<Bind: #{bind_values.inspect}>" unless bind_values.empty?)
        ]
      )
    end
  end
rescue RDO::Exception => e
  logger.fatal(e.message) if logger.fatal?
  raise
end