Class: ActiveRecord::ConnectionAdapters::OracleEnhancedOCIFactory

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

Overview

The OracleEnhancedOCIFactory factors out the code necessary to connect and configure an Oracle/OCI connection.

Class Method Summary collapse

Class Method Details

.new_connection(config) ⇒ Object

:nodoc:



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 194

def self.new_connection(config)
  username, password, database = config[:username].to_s, config[:password].to_s, config[:database].to_s
  privilege = config[:privilege] && config[:privilege].to_sym
  async = config[:allow_concurrency]
  prefetch_rows = config[:prefetch_rows] || 100
  cursor_sharing = config[:cursor_sharing] || 'similar'
  # by default VARCHAR2 column size will be interpreted as max number of characters (and not bytes)
  nls_length_semantics = config[:nls_length_semantics] || 'CHAR'

  conn = OCI8.new username, password, database, privilege
  conn.exec %q{alter session set nls_date_format = 'YYYY-MM-DD HH24:MI:SS'}
  conn.exec %q{alter session set nls_timestamp_format = 'YYYY-MM-DD HH24:MI:SS'} rescue nil
  conn.autocommit = true
  conn.non_blocking = true if async
  conn.prefetch_rows = prefetch_rows
  conn.exec "alter session set cursor_sharing = #{cursor_sharing}" rescue nil
  conn.exec "alter session set nls_length_semantics = '#{nls_length_semantics}'"
  conn
end