Class: ActiveRecord::ConnectionAdapters::OracleEnhancedOCIConnection
- Inherits:
-
OracleEnhancedConnection
- Object
- OracleEnhancedConnection
- ActiveRecord::ConnectionAdapters::OracleEnhancedOCIConnection
- 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
Instance Method Summary collapse
- #active? ⇒ Boolean
- #auto_retry ⇒ Object
- #auto_retry=(value) ⇒ Object
- #autocommit=(value) ⇒ Object
- #autocommit? ⇒ Boolean
- #commit ⇒ Object
- #describe(name) ⇒ Object
-
#error_code(exception) ⇒ Object
Return OCIError error code.
- #exec(sql, *bindvars, &block) ⇒ Object
-
#exec_with_returning(sql) ⇒ Object
execute sql with RETURNING …
-
#initialize(config) ⇒ OracleEnhancedOCIConnection
constructor
:nodoc:.
- #logoff ⇒ Object
-
#ping ⇒ Object
Checks connection, returns true if active.
- #reset! ⇒ Object
- #returning_clause(quoted_pk) ⇒ Object
- #rollback ⇒ Object
- #select(sql, name = nil, return_column_names = false) ⇒ Object
- #write_lob(lob, value, is_binary = false) ⇒ Object
Methods inherited from OracleEnhancedConnection
Constructor Details
#initialize(config) ⇒ OracleEnhancedOCIConnection
:nodoc:
30 31 32 33 34 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 30 def initialize(config) @raw_connection = OCI8EnhancedAutoRecover.new(config, OracleEnhancedOCIFactory) # default schema owner @owner = config[:username].to_s.upcase end |
Instance Method Details
#active? ⇒ Boolean
74 75 76 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 74 def active? @raw_connection.active? end |
#auto_retry ⇒ Object
36 37 38 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 36 def auto_retry @raw_connection.auto_retry if @raw_connection end |
#auto_retry=(value) ⇒ Object
40 41 42 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 40 def auto_retry=(value) @raw_connection.auto_retry = value if @raw_connection end |
#autocommit=(value) ⇒ Object
61 62 63 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 61 def autocommit=(value) @raw_connection.autocommit = value end |
#autocommit? ⇒ Boolean
57 58 59 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 57 def autocommit? @raw_connection.autocommit? end |
#commit ⇒ Object
49 50 51 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 49 def commit @raw_connection.commit end |
#describe(name) ⇒ Object
136 137 138 139 140 141 142 143 144 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 136 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
147 148 149 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 147 def error_code(exception) exception.code end |
#exec(sql, *bindvars, &block) ⇒ Object
84 85 86 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 84 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
94 95 96 97 98 99 100 101 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 94 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 |
#logoff ⇒ Object
44 45 46 47 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 44 def logoff @raw_connection.logoff @raw_connection.active = false end |
#ping ⇒ Object
Checks connection, returns true if active. Note that ping actively checks the connection, while #active? simply returns the last known state.
68 69 70 71 72 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 68 def ping @raw_connection.ping rescue OCIException => e raise OracleEnhancedConnectionException, e. end |
#reset! ⇒ Object
78 79 80 81 82 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 78 def reset! @raw_connection.reset! rescue OCIException => e raise OracleEnhancedConnectionException, e. end |
#returning_clause(quoted_pk) ⇒ Object
88 89 90 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 88 def returning_clause(quoted_pk) " RETURNING #{quoted_pk} INTO :insert_id" end |
#rollback ⇒ Object
53 54 55 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 53 def rollback @raw_connection.rollback end |
#select(sql, name = nil, return_column_names = false) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 103 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
132 133 134 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 132 def write_lob(lob, value, is_binary = false) lob.write value end |