class SCAnalytics::Connections::Oracle

Attributes

connect_string[R]
service_name[R]
sid[R]

Public Class Methods

new(connection_name, config) click to toggle source
# File lib/sc_analytics/connections/oracle.rb, line 10
def initialize(connection_name, config)
        super

        @host = config[:connection][:description][:address][:host]
        @port = config[:connection][:description][:address][:port]
        @service_name = config[:connection][:description][:connect_data][:service_name]
        @sid = config[:connection][:description][:connect_data][:sid]

        @connect_string = generate_connect_string_for(config[:connection])
        connect
end

Public Instance Methods

connect() click to toggle source
# File lib/sc_analytics/connections/oracle.rb, line 48
def connect
        super do
                @client = OCI8.new @username, @password, @connect_string
        end
end
define_col_types_for(query, cursor) click to toggle source
# File lib/sc_analytics/connections/oracle.rb, line 22
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
generate_connect_string_for(conn_hsh, conn_str = "") click to toggle source
# File lib/sc_analytics/connections/oracle.rb, line 54
def generate_connect_string_for(conn_hsh, conn_str = "")
        conn_hsh.each_pair do |descriptor,detail|
                conn_str << "("
                conn_str << "#{descriptor.to_s}="
                detail.is_a?(Hash) ? conn_str = generate_connect_string_for(detail, conn_str) : conn_str << detail.to_s
                conn_str << ")"
        end
        conn_str
end
get_cursor_for(query) click to toggle source
# File lib/sc_analytics/connections/oracle.rb, line 30
def get_cursor_for(query)
        cursor = @client.parse(query.sql)
end
run(query, cursor) click to toggle source
# File lib/sc_analytics/connections/oracle.rb, line 34
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