Class: ActiveRecord::ConnectionAdapters::OracleEnhancedOCIConnection

Inherits:
OracleEnhancedConnection show all
Defined in:
lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb

Overview

OCI database interface for MRI

Instance Attribute Summary

Attributes inherited from OracleEnhancedConnection

#raw_connection

Instance Method Summary collapse

Methods inherited from OracleEnhancedConnection

create, #oracle_downcase

Constructor Details

#initialize(config) ⇒ OracleEnhancedOCIConnection

:nodoc:



23
24
25
26
27
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 23

def initialize(config)
  @raw_connection = OCI8EnhancedAutoRecover.new(config, OracleEnhancedOCIFactory)
  # default schema owner
  @owner = config[:username].to_s.upcase
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 67

def active?
  @raw_connection.active?
end

#auto_retryObject



29
30
31
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 29

def auto_retry
  @raw_connection.auto_retry if @raw_connection
end

#auto_retry=(value) ⇒ Object



33
34
35
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 33

def auto_retry=(value)
  @raw_connection.auto_retry = value if @raw_connection
end

#autocommit=(value) ⇒ Object



54
55
56
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 54

def autocommit=(value)
  @raw_connection.autocommit = value
end

#autocommit?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 50

def autocommit?
  @raw_connection.autocommit?
end

#commitObject



42
43
44
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 42

def commit
  @raw_connection.commit
end

#describe(name) ⇒ Object



129
130
131
132
133
134
135
136
137
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 129

def describe(name)
  # fall back to SELECT based describe if using database link
  return super if name.to_s.include?('@')
  quoted_name = OracleEnhancedAdapter.valid_table_name?(name) ? name : "\"#{name}\""
  @raw_connection.describe(quoted_name)
rescue OCIException => e
  # fall back to SELECT which can handle synonyms to database links
  super
end

#error_code(exception) ⇒ Object

Return OCIError error code



140
141
142
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 140

def error_code(exception)
  exception.code
end

#exec(sql, *bindvars, &block) ⇒ Object



77
78
79
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 77

def exec(sql, *bindvars, &block)
  @raw_connection.exec(sql, *bindvars, &block)
end

#exec_with_returning(sql) ⇒ Object

execute sql with RETURNING … INTO :insert_id and return :insert_id value



87
88
89
90
91
92
93
94
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 87

def exec_with_returning(sql)
  cursor = @raw_connection.parse(sql)
  cursor.bind_param(':insert_id', nil, Integer)
  cursor.exec
  cursor[':insert_id']
ensure
  cursor.close rescue nil
end

#logoffObject



37
38
39
40
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 37

def logoff
  @raw_connection.logoff
  @raw_connection.active = false
end

#pingObject

Checks connection, returns true if active. Note that ping actively checks the connection, while #active? simply returns the last known state.



61
62
63
64
65
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 61

def ping
  @raw_connection.ping
rescue OCIException => e
  raise OracleEnhancedConnectionException, e.message
end

#reset!Object



71
72
73
74
75
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 71

def reset!
  @raw_connection.reset!
rescue OCIException => e
  raise OracleEnhancedConnectionException, e.message
end

#returning_clause(quoted_pk) ⇒ Object



81
82
83
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 81

def returning_clause(quoted_pk)
  " RETURNING #{quoted_pk} INTO :insert_id"
end

#rollbackObject



46
47
48
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 46

def rollback
  @raw_connection.rollback
end

#select(sql, name = nil, return_column_names = false) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 96

def select(sql, name = nil, return_column_names = false)
  cursor = @raw_connection.exec(sql)
  cols = []
  # Ignore raw_rnum_ which is used to simulate LIMIT and OFFSET
  cursor.get_col_names.each do |col_name|
    col_name = oracle_downcase(col_name)
    cols << col_name unless col_name == 'raw_rnum_'
  end
  # Reuse the same hash for all rows
  column_hash = {}
  cols.each {|c| column_hash[c] = nil}
  rows = []
  get_lob_value = !(name == 'Writable Large Object')

  while row = cursor.fetch
    hash = column_hash.dup

    cols.each_with_index do |col, i|
      hash[col] = typecast_result_value(row[i], get_lob_value)
    end

    rows << hash
  end

  return_column_names ? [rows, cols] : rows
ensure
  cursor.close if cursor
end

#write_lob(lob, value, is_binary = false) ⇒ Object



125
126
127
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 125

def write_lob(lob, value, is_binary = false)
  lob.write value
end