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:



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 182

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'

  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
end