Class: Avmtrf1::Oracle::Connection::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/avmtrf1/oracle/connection/base.rb

Constant Summary collapse

DEFAULT_PORT =
1521

Instance Method Summary collapse

Constructor Details

#initialize(connection_string) ⇒ Base

Returns a new instance of Base.


14
15
16
17
# File 'lib/avmtrf1/oracle/connection/base.rb', line 14

def initialize(connection_string)
  ::Avmtrf1::Oracle::Oci8.require_lib
  @connection = OCI8.new(connection_string)
end

Instance Method Details

#first_row(sql) ⇒ Object


19
20
21
22
# File 'lib/avmtrf1/oracle/connection/base.rb', line 19

def first_row(sql)
  connection.exec(sql) { |row| return row }
  nil
end

#first_row_hash(sql) ⇒ Object


24
25
26
27
# File 'lib/avmtrf1/oracle/connection/base.rb', line 24

def first_row_hash(sql)
  connection.exec(sql).fetch_hash { |row| return row }
  nil
end

#objectsObject


41
42
43
# File 'lib/avmtrf1/oracle/connection/base.rb', line 41

def objects
  @objects ||= ::Avmtrf1::Oracle::Objects.new(self)
end

#query(sql, &block) ⇒ Object


33
34
35
36
37
38
39
# File 'lib/avmtrf1/oracle/connection/base.rb', line 33

def query(sql, &block)
  if block
    query_with_block(sql, block)
  else
    query_without_block(sql)
  end
end

#unique_value(sql) ⇒ Object


29
30
31
# File 'lib/avmtrf1/oracle/connection/base.rb', line 29

def unique_value(sql)
  first_row(sql).if_present(&:first)
end