Class: DBGeni::Connector::Oracle

Inherits:
Object
  • Object
show all
Defined in:
lib/dbgeni/connectors/oracle.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



15
16
17
# File 'lib/dbgeni/connectors/oracle.rb', line 15

def connection
  @connection
end

#databaseObject (readonly)

Returns the value of attribute database.



16
17
18
# File 'lib/dbgeni/connectors/oracle.rb', line 16

def database
  @database
end

Class Method Details

.connect(user, password, database, host = nil, port = nil) ⇒ Object



18
19
20
# File 'lib/dbgeni/connectors/oracle.rb', line 18

def self.connect(user, password, database, host=nil, port=nil)
  self.new(user, password, database, host, port)
end

Instance Method Details

#commitObject



70
71
72
# File 'lib/dbgeni/connectors/oracle.rb', line 70

def commit
  @connection.commit
end

#date_as_string(dtm) ⇒ Object



82
83
84
# File 'lib/dbgeni/connectors/oracle.rb', line 82

def date_as_string(dtm)
  dtm.strftime '%Y%m%d%H%M%S'
end

#date_placeholder(bind_var) ⇒ Object



78
79
80
# File 'lib/dbgeni/connectors/oracle.rb', line 78

def date_placeholder(bind_var)
  "to_date(:#{bind_var}, 'YYYYMMDDHH24MISS')"
end

#disconnectObject



22
23
24
# File 'lib/dbgeni/connectors/oracle.rb', line 22

def disconnect
  @connection.logoff
end

#execute(sql, *binds) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/dbgeni/connectors/oracle.rb', line 26

def execute(sql, *binds)
  if RUBY_PLATFORM == 'java'
    return execute_jdbc(sql, *binds)
  end

  begin
    # OCI doesn't like the ? bind variables, so need to convert them
    index = 0
    new_sql = sql.gsub(/\?/) do |m|
      index += 1
      ":b#{index.to_s}"
    end

    query = @connection.parse(new_sql)
    query.exec(*binds)

    results = nil
    if query.type == OCI8::STMT_SELECT
      results = Array.new
      while r = query.fetch()
        results.push r
      end
    else
      # everthing is auto commit right now ...
      @connection.commit
    end
  ensure
    begin
      query.close()
    rescue
    end
  end
  results
end

#pingObject



61
62
63
64
65
66
67
68
# File 'lib/dbgeni/connectors/oracle.rb', line 61

def ping
  results = self.execute('select dummy from dual')
  if results.length == 1
    true
  else
    false
  end
end

#rollbackObject



74
75
76
# File 'lib/dbgeni/connectors/oracle.rb', line 74

def rollback
  @connection.rollback
end