Class: JDBCHelpers::Execute

Inherits:
Base
  • Object
show all
Defined in:
lib/jdbc_helpers.rb

Overview

executes a sql statement

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#cleanse_statement, #convert_to_string_classes

Constructor Details

#initialize(db_connect, statement, logger = nil) ⇒ Execute

Returns a new instance of Execute

Parameters:

  • db_connect (Object)

    active connection against which to execute statement

  • statement (String)

    SQL statement text

  • logger (Logger) (defaults to: nil)

    object otherwise will default to new Logger



59
60
61
62
63
64
65
66
67
68
# File 'lib/jdbc_helpers.rb', line 59

def initialize(db_connect, statement, logger = nil)
  @logger = logger ? logger : Logger.new(STDOUT)
  stmt = db_connect.create_statement
  @logger.info(
    "executing statement: #{cleanse_statement(statement)}"
  )
  start = Time.new.utc
  @rows_affected = stmt.execute_update(statement)
  @logger.info "query executed #{Time.new.utc - start} seconds"
end

Instance Attribute Details

#rows_affectedObject

Rows affected by the SQL statement execution. Note that not all JDBC drivers/databases handle this appropriately



54
55
56
# File 'lib/jdbc_helpers.rb', line 54

def rows_affected
  @rows_affected
end