Class: ActiveRecord::ConnectionAdapters::OracleEnhancedOCIFactory
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::OracleEnhancedOCIFactory
- 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
-
.new_connection(config) ⇒ Object
:nodoc:.
Class Method Details
.new_connection(config) ⇒ Object
:nodoc:
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb', line 212 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] || 'force' # by default VARCHAR2 column size will be interpreted as max number of characters (and not bytes) nls_length_semantics = config[:nls_length_semantics] || 'CHAR' # get session time_zone from configuration or from TZ environment variable time_zone = config[:time_zone] || ENV['TZ'] 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:FF6'} 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.exec "alter session set time_zone = '#{time_zone}'" unless time_zone.blank? conn end |