Sha256: 11027d194f4d3fda6942a6fe98239d38fc2035443f9e77482f6ca9823863a0cb

Contents?: true

Size: 1.24 KB

Versions: 59

Compression:

Stored size: 1.24 KB

Contents

#
# setup default OCI encoding from NLS_LANG.
#

#
class OCI8

  @@client_charset_name = charset_id2name(@@environment_handle.send(:attr_get_ub2, 31))
  # 31 is OCI_ATTR_ENV_CHARSET_ID.

  if @@client_charset_name == 'US7ASCII'
    # Check whether US7ASCII is explicitly set by NLS_LANG or not.
    nls_lang = ENV['NLS_LANG']
    if nls_lang.nil? and defined? OCI8::Win32Util
      if OCI8::Util::dll_path =~ /\\BIN\\OCI\.DLL$/i
        oracle_home = $`
        OCI8::Win32Util.enum_homes do |home, lang|
          if oracle_home == home.upcase
            nls_lang = lang
            break
          end
        end
      end
    end
    if nls_lang.nil?
      warn "Warning: NLS_LANG is not set. fallback to US7ASCII."
    end
  end

  if defined? DEFAULT_OCI8_ENCODING
    enc = DEFAULT_OCI8_ENCODING
  else
    require 'yaml'
    yaml_file = File.dirname(__FILE__) + '/encoding.yml'
    enc = YAML::load_file(yaml_file)[@@client_charset_name]
    if enc.nil?
      raise "Cannot convert Oracle charset name #{@@client_charset_name} to Ruby encoding name in #{yaml_file}."
    end
    if enc.is_a? Array
      # Use the first available encoding in the array.
      enc = enc.find do |e| Encoding.find(e) rescue false; end
    end
  end
  OCI8.encoding = enc
end

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
ruby-oci8-2.2.14 lib/oci8/encoding-init.rb
ruby-oci8-2.2.13-x86-mingw32 lib/oci8/encoding-init.rb
ruby-oci8-2.2.13-x64-mingw32 lib/oci8/encoding-init.rb
ruby-oci8-2.2.13-x64-mingw-ucrt lib/oci8/encoding-init.rb
ruby-oci8-2.2.13 lib/oci8/encoding-init.rb
ruby-oci8-2.2.12-x64-mingw32 lib/oci8/encoding-init.rb
ruby-oci8-2.2.12-x64-mingw-ucrt lib/oci8/encoding-init.rb
ruby-oci8-2.2.12-x86-mingw32 lib/oci8/encoding-init.rb
ruby-oci8-2.2.12 lib/oci8/encoding-init.rb
ruby-oci8-2.2.11 lib/oci8/encoding-init.rb
ruby-oci8-2.2.11-x64-mingw-ucrt lib/oci8/encoding-init.rb
ruby-oci8-2.2.11-x64-mingw32 lib/oci8/encoding-init.rb
ruby-oci8-2.2.11-x86-mingw32 lib/oci8/encoding-init.rb
ruby-oci8-2.2.10-x64-mingw-ucrt lib/oci8/encoding-init.rb
ruby-oci8-2.2.10 lib/oci8/encoding-init.rb
ruby-oci8-2.2.10-x86-mingw32 lib/oci8/encoding-init.rb
ruby-oci8-2.2.10-x64-mingw32 lib/oci8/encoding-init.rb
ruby-oci8-2.2.9 lib/oci8/encoding-init.rb
ruby-oci8-2.2.9-x86-mingw32 lib/oci8/encoding-init.rb
ruby-oci8-2.2.9-x64-mingw32 lib/oci8/encoding-init.rb