Class: SCAnalytics::Connections::Oracle

Inherits:
Connection
  • Object
show all
Defined in:
lib/sc_analytics/connections/oracle.rb

Instance Attribute Summary

Attributes inherited from Connection

#host, #port, #service, #username

Instance Method Summary collapse

Constructor Details

#initialize(connection_name, options) ⇒ Oracle

Returns a new instance of Oracle.



7
8
9
10
11
12
# File 'lib/sc_analytics/connections/oracle.rb', line 7

def initialize(connection_name, options)
  super

  parse_db_url
  connect
end

Instance Method Details

#connectObject



40
41
42
43
44
# File 'lib/sc_analytics/connections/oracle.rb', line 40

def connect
  super do
    @client = OCI8.new @username, @password, @db_url
  end
end

#define_col_types_for(query, cursor) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/sc_analytics/connections/oracle.rb', line 14

def define_col_types_for(query, cursor)
  (query.columns_to_cast || {}).each_pair do |type, cols|
    cols.each do |col|
      cursor.define(col, type)
    end
  end
end

#get_cursor_for(query) ⇒ Object



22
23
24
# File 'lib/sc_analytics/connections/oracle.rb', line 22

def get_cursor_for(query)
  cursor = @client.parse(query.sql)
end

#parse_db_urlObject



46
47
48
49
50
51
52
53
54
# File 'lib/sc_analytics/connections/oracle.rb', line 46

def parse_db_url
  url = []
  url << "//#{@host}" if @host
  url << ":#{@port}" if @port
  url << "/" if @host
  url << @service

  @db_url = url.join
end

#run(query, cursor) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sc_analytics/connections/oracle.rb', line 26

def run(query, cursor)
  cursor.exec
  define_col_types_for query, cursor

  headers = cursor.get_col_names
  results = []
  
  while row = cursor.fetch
    results << row
  end

  Struct::QueryResult.new(headers, results)
end