ruby-oci8 2.1.8-x64-mingw32 → 2.2.0-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,99 @@
1
+ # This file is loaded only on LoadError.
2
+
3
+ class OCI8
4
+ module Util
5
+
6
+ case RUBY_PLATFORM
7
+ when /mswin32|cygwin|mingw32|bccwin32/
8
+
9
+ require 'Win32API'
10
+ MAX_PATH = 260
11
+ GetModuleFileNameA = Win32API.new('kernel32', 'GetModuleFileNameA', 'PPL', 'L')
12
+ GetSystemDirectoryA = Win32API.new('kernel32', 'GetSystemDirectoryA', 'PL', 'L')
13
+ GetWindowsDirectoryA = Win32API.new('kernel32', 'GetWindowsDirectoryA', 'PL', 'L')
14
+
15
+ def self.check_os_specific_load_error(exc)
16
+ case exc.message
17
+ when /^193: / # "193: %1 is not a valid Win32 application." in English
18
+ check_win32_pe_arch(exc.message.split(' - ')[1], "ruby-oci8")
19
+ dll_load_path_list.each do |path|
20
+ check_win32_pe_arch(File.join(path, '\OCI.DLL'), "Oracle client")
21
+ end
22
+ end
23
+ end # self.check_os_specific_load_error
24
+
25
+ def self.dll_load_path_list
26
+ buf = "\0" * MAX_PATH
27
+ paths = []
28
+ paths << buf[0, GetModuleFileNameA.call(nil, buf, MAX_PATH)].force_encoding("locale").gsub(/\\[^\\]*$/, '')
29
+ paths << buf[0, GetSystemDirectoryA.call(buf, MAX_PATH)].force_encoding("locale")
30
+ paths << buf[0, GetWindowsDirectoryA.call(buf, MAX_PATH)].force_encoding("locale")
31
+ paths << "."
32
+ paths + ENV['PATH'].split(';')
33
+ end # self.dll_load_path_list
34
+
35
+ def self.check_win32_pe_arch(filename, package)
36
+ open(filename, 'rb') do |f|
37
+ # DOS header.
38
+ if f.read(2) == 'MZ'
39
+ f.seek(60, IO::SEEK_SET)
40
+ pe_offset = f.read(4).unpack('V')[0]
41
+ f.seek(pe_offset)
42
+ # PE header.
43
+ if f.read(4) == "PE\000\000"
44
+ case f.read(2).unpack('v')[0]
45
+ when 0x8664
46
+ if [nil].pack('P').size == 4
47
+ raise LoadError, "\"#{filename}\" is x64 DLL. Use 32-bit #{package} instead."
48
+ end
49
+ return true
50
+ when 0x014c
51
+ if [nil].pack('P').size == 8
52
+ raise LoadError, "\"#{filename}\" is 32-bit DLL. Use x64 #{package} instead."
53
+ end
54
+ return true
55
+ end
56
+ end
57
+ end
58
+ raise LoadError, "\"#{filename}\" is not a valid Win32 application."
59
+ end
60
+ nil
61
+ rescue
62
+ nil
63
+ end # self.check_win32_pe_arch
64
+
65
+ when /linux/
66
+
67
+ def self.check_os_specific_load_error(exc)
68
+ case exc.message
69
+ when /^libaio\.so\.1:/ # "libaio.so.1: cannot open shared object file: No such file or directory" in English
70
+ install_cmd = if File.executable? '/usr/bin/apt-get'
71
+ 'apt-get install libaio1'
72
+ elsif File.executable? '/usr/bin/yum'
73
+ 'yum install libaio'
74
+ end
75
+ if install_cmd
76
+ raise LoadError, "You need to install libaio.so.1. Run '#{install_cmd}'."
77
+ else
78
+ raise LoadError, "You need to install libaio.so.1."
79
+ end
80
+ end
81
+ end # self.check_os_specific_load_error
82
+
83
+ else
84
+
85
+ def self.check_os_specific_load_error(exc)
86
+ end
87
+
88
+ end # case RUBY_PLATFORM
89
+
90
+ def self.check_load_error(exc)
91
+ check_os_specific_load_error(exc)
92
+ case exc.message
93
+ when /^OCI Library Initialization Error/
94
+ # TODO
95
+ end
96
+ end
97
+
98
+ end # module Util
99
+ end
@@ -5,75 +5,41 @@
5
5
  #
6
6
  class OCI8
7
7
 
8
- # get the environment variable NLS_LANG.
9
- nls_lang = ENV['NLS_LANG']
8
+ @@client_charset_name = charset_id2name(@@environment_handle.send(:attr_get_ub2, 31))
9
+ # 31 is OCI_ATTR_ENV_CHARSET_ID.
10
10
 
11
- if nls_lang.is_a? String and nls_lang.length == 0
12
- nls_lang = nil
13
- end
14
-
15
- # if NLS_LANG is not set, get it from the Windows registry.
16
- if nls_lang.nil? and defined? OCI8::Win32Util
17
- dll_path = OCI8::Win32Util.dll_path.upcase
18
- if dll_path =~ %r{\\BIN\\OCI.DLL}
19
- oracle_home = $`
20
- OCI8::Win32Util.enum_homes do |home, lang|
21
- if oracle_home == home.upcase
22
- nls_lang = lang
23
- break
11
+ if @@client_charset_name == 'US7ASCII'
12
+ # Check whether US7ASCII is explicitly set by NLS_LANG or not.
13
+ nls_lang = ENV['NLS_LANG']
14
+ if nls_lang.nil? and defined? OCI8::Win32Util
15
+ if OCI8::Util::dll_path =~ /\\BIN\\OCI\.DLL$/i
16
+ oracle_home = $`
17
+ OCI8::Win32Util.enum_homes do |home, lang|
18
+ if oracle_home == home.upcase
19
+ nls_lang = lang
20
+ break
21
+ end
24
22
  end
25
23
  end
26
24
  end
27
- end
28
-
29
- # extract the charset name.
30
- if nls_lang
31
- if nls_lang =~ /\.([[:alnum:]]+)$/
32
- @@client_charset_name = $1.upcase
33
- else
34
- raise "Invalid NLS_LANG format: #{nls_lang}"
25
+ if nls_lang.nil?
26
+ warn "Warning: NLS_LANG is not set. fallback to US7ASCII."
35
27
  end
36
- else
37
- warn "Warning: NLS_LANG is not set. fallback to US7ASCII."
38
- # @private
39
- @@client_charset_name = 'US7ASCII'
40
28
  end
41
29
 
42
- # Ruby encoding name for ruby 1.9.
43
- if OCI8.respond_to? :encoding
44
- if defined? DEFAULT_OCI8_ENCODING
45
- enc = DEFAULT_OCI8_ENCODING
46
- else
47
- require 'yaml'
48
- enc = YAML::load_file(File.dirname(__FILE__) + '/encoding.yml')[@@client_charset_name]
49
- if enc.nil?
50
- raise "Ruby encoding name is not found in encoding.yml for NLS_LANG #{nls_lang}."
51
- end
52
- if enc.is_a? Array
53
- # Use the first available encoding in the array.
54
- enc = enc.find do |e| Encoding.find(e) rescue false; end
55
- end
56
- end
57
- OCI8.encoding = enc
30
+ if defined? DEFAULT_OCI8_ENCODING
31
+ enc = DEFAULT_OCI8_ENCODING
58
32
  else
59
- # NLS ratio, maximum number of bytes per one chracter
60
- case @@client_charset_name
61
- when 'UTF8'
62
- OCI8.nls_ratio = 3
63
- when 'AL16UTF16'
64
- OCI8.nls_ratio = 4
65
- when /^[[:alpha:]]+(\d+)/
66
- # convert maximum number of bits per one chracter to NLS ratio.
67
- # charset name max bits max bytes
68
- # ------------ -------- ---------
69
- # US7ASCII 7 1
70
- # WE8ISO8859P1 8 1
71
- # JA16SJIS 16 2
72
- # AL32UTF8 32 4
73
- # ...
74
- OCI8.nls_ratio = (($1.to_i + 7) >> 3)
75
- else
76
- raise "Unknown NLS character set name format: #{@@client_charset_name}"
33
+ require 'yaml'
34
+ yaml_file = File.dirname(__FILE__) + '/encoding.yml'
35
+ enc = YAML::load_file(yaml_file)[@@client_charset_name]
36
+ if enc.nil?
37
+ raise "Cannot convert Oracle charset name #{@@client_charset_name} to Ruby encoding name in #{yaml_file}."
38
+ end
39
+ if enc.is_a? Array
40
+ # Use the first available encoding in the array.
41
+ enc = enc.find do |e| Encoding.find(e) rescue false; end
77
42
  end
78
43
  end
44
+ OCI8.encoding = enc
79
45
  end
@@ -996,20 +996,14 @@ class OCI8
996
996
  __charset_form
997
997
  end
998
998
 
999
- if OCI8.oracle_client_version >= ORAVER_9_0
1000
- # The fractional seconds precision of a datetime or interval.
1001
- #
1002
- # (unavailable on Oracle 8.1 or lower)
1003
- def fsprecision
1004
- attr_get_ub1(OCI_ATTR_FSPRECISION)
1005
- end
999
+ # The fractional seconds precision of a datetime or interval.
1000
+ def fsprecision
1001
+ attr_get_ub1(OCI_ATTR_FSPRECISION)
1002
+ end
1006
1003
 
1007
- # The leading field precision of an interval
1008
- #
1009
- # (unavailable on Oracle 8.1 or lower)
1010
- def lfprecision
1011
- attr_get_ub1(OCI_ATTR_LFPRECISION)
1012
- end
1004
+ # The leading field precision of an interval
1005
+ def lfprecision
1006
+ attr_get_ub1(OCI_ATTR_LFPRECISION)
1013
1007
  end
1014
1008
 
1015
1009
  # character set name if the type attribute is of a string/character type.
@@ -1339,30 +1333,18 @@ class OCI8
1339
1333
 
1340
1334
  ## Table 6-13 Attributes Belonging to Columns of Tables or Views
1341
1335
 
1342
- if OCI8.oracle_client_version >= ORAVER_9_0
1343
- # returns the type of length semantics of the column.
1344
- # [<tt>:byte</tt>] byte-length semantics
1345
- # [<tt>:char</tt>] character-length semantics.
1346
- #
1347
- # (unavailable on Oracle 8.1 or lower)
1348
- def char_used?
1349
- attr_get_ub1(OCI_ATTR_CHAR_USED) != 0
1350
- end
1351
-
1352
- # returns the column character length which is the number of
1353
- # characters allowed in the column. It is the counterpart of
1354
- # OCI8::Metadata::Column#data_size which gets the byte length.
1355
- def char_size
1356
- attr_get_ub2(OCI_ATTR_CHAR_SIZE)
1357
- end
1358
- else
1359
- def char_used?
1360
- false
1361
- end
1336
+ # returns the type of length semantics of the column.
1337
+ # [<tt>:byte</tt>] byte-length semantics
1338
+ # [<tt>:char</tt>] character-length semantics.
1339
+ def char_used?
1340
+ attr_get_ub1(OCI_ATTR_CHAR_USED) != 0
1341
+ end
1362
1342
 
1363
- def char_size
1364
- data_size
1365
- end
1343
+ # returns the column character length which is the number of
1344
+ # characters allowed in the column. It is the counterpart of
1345
+ # OCI8::Metadata::Column#data_size which gets the byte length.
1346
+ def char_size
1347
+ attr_get_ub2(OCI_ATTR_CHAR_SIZE)
1366
1348
  end
1367
1349
 
1368
1350
  # The maximum size of the column. This length is
@@ -1445,20 +1427,14 @@ class OCI8
1445
1427
  ## Table 6-8 Attributes Belonging to Type Attributes
1446
1428
  ## But Column also have these.
1447
1429
 
1448
- if OCI8.oracle_client_version >= ORAVER_9_0
1449
- # The fractional seconds precision of a datetime or interval.
1450
- #
1451
- # (unavailable on Oracle 8.1 or lower)
1452
- def fsprecision
1453
- attr_get_ub1(OCI_ATTR_FSPRECISION)
1454
- end
1430
+ # The fractional seconds precision of a datetime or interval.
1431
+ def fsprecision
1432
+ attr_get_ub1(OCI_ATTR_FSPRECISION)
1433
+ end
1455
1434
 
1456
- # The leading field precision of an interval
1457
- #
1458
- # (unavailable on Oracle 8.1 or lower)
1459
- def lfprecision
1460
- attr_get_ub1(OCI_ATTR_LFPRECISION)
1461
- end
1435
+ # The leading field precision of an interval
1436
+ def lfprecision
1437
+ attr_get_ub1(OCI_ATTR_LFPRECISION)
1462
1438
  end
1463
1439
 
1464
1440
  # The character set name, if the column is of a string/character type
@@ -1677,14 +1653,8 @@ class OCI8
1677
1653
 
1678
1654
  ## Table 6-15 List Attributes
1679
1655
 
1680
- if OCI8::oracle_client_version < OCI8::ORAVER_8_1
1681
- def ltype
1682
- raise "This feature is unavailable on Oracle 8.0"
1683
- end
1684
- else
1685
- def ltype
1686
- attr_get_ub2(OCI_ATTR_LTYPE)
1687
- end
1656
+ def ltype
1657
+ attr_get_ub2(OCI_ATTR_LTYPE)
1688
1658
  end
1689
1659
 
1690
1660
  # convert to array
@@ -1,6 +1,6 @@
1
1
  # oci8.rb -- OCI8
2
2
  #
3
- # Copyright (C) 2002-2013 Kubo Takehiro <kubo@jiubao.org>
3
+ # Copyright (C) 2002-2015 Kubo Takehiro <kubo@jiubao.org>
4
4
  #
5
5
  # Original Copyright is:
6
6
  # Oracle module for Ruby
@@ -140,10 +140,12 @@ class OCI8
140
140
  @session_handle.send(:attr_set_string, OCI_ATTR_USERNAME, username) if username
141
141
  @session_handle.send(:attr_set_string, OCI_ATTR_PASSWORD, password) if password
142
142
  if @@oracle_client_version >= ORAVER_11_1
143
- # 'rubyoci8' is displayed in V$SESSION_CONNECT_INFO.CLIENT_DRIVER
143
+ # Sets the driver name displayed in V$SESSION_CONNECT_INFO.CLIENT_DRIVER
144
144
  # if both the client and the server are Oracle 11g or upper.
145
+ # Only the first 8 chracters "ruby-oci" are displayed when the Oracle
146
+ # server version is lower than 12.0.1.2.
145
147
  # 424: OCI_ATTR_DRIVER_NAME
146
- @session_handle.send(:attr_set_string, 424, 'rubyoci8')
148
+ @session_handle.send(:attr_set_string, 424, "ruby-oci8 : #{OCI8::VERSION}")
147
149
  end
148
150
  server_attach(dbname, attach_mode)
149
151
  session_begin(cred ? cred : OCI_CRED_RDBMS, mode ? mode : OCI_DEFAULT)
@@ -157,7 +159,7 @@ class OCI8
157
159
  attr_set_ub4(176, stmt_cache_size) # 176: OCI_ATTR_STMTCACHESIZE
158
160
  end
159
161
 
160
- @prefetch_rows = nil
162
+ @prefetch_rows = 100
161
163
  @username = nil
162
164
  end
163
165
 
@@ -329,12 +331,12 @@ class OCI8
329
331
  end
330
332
  end
331
333
 
332
- # Sets the prefetch rows size. The default value is one.
334
+ # Sets the prefetch rows size. The default value is 100.
333
335
  # When a select statement is executed, the OCI library allocate
334
336
  # prefetch buffer to reduce the number of network round trips by
335
337
  # retrieving specified number of rows in one round trip.
336
338
  #
337
- # Note: Active record adaptors set 100 by default.
339
+ # Note: The default value had been 1 before ruby-oci8 2.2.0.
338
340
  def prefetch_rows=(num)
339
341
  @prefetch_rows = num
340
342
  end
@@ -531,19 +533,16 @@ class OraDate
531
533
  Date.new(year, month, day)
532
534
  end
533
535
 
534
- if defined? DateTime # ruby 1.8.0 or upper
535
-
536
- # timezone offset of the time the command started
537
- # @private
538
- @@tz_offset = Time.now.utc_offset.to_r/86400
536
+ # timezone offset of the time the command started
537
+ # @private
538
+ @@tz_offset = Time.now.utc_offset.to_r/86400
539
539
 
540
- # Returns a DateTime object which denotes self.
541
- #
542
- # Note that this is not daylight saving time aware.
543
- # The Time zone offset is that of the time the command started.
544
- def to_datetime
545
- DateTime.new(year, month, day, hour, minute, second, @@tz_offset)
546
- end
540
+ # Returns a DateTime object which denotes self.
541
+ #
542
+ # Note that this is not daylight saving time aware.
543
+ # The Time zone offset is that of the time the command started.
544
+ def to_datetime
545
+ DateTime.new(year, month, day, hour, minute, second, @@tz_offset)
547
546
  end
548
547
 
549
548
  # @private
@@ -15,10 +15,6 @@ class OCI8
15
15
  :cancel_read_at_exit => false,
16
16
  }
17
17
 
18
- if OCI8.oracle_client_version < OCI8::ORAVER_9_2
19
- @@properties[:statement_cache_size] = nil
20
- end
21
-
22
18
  # @private
23
19
  def @@properties.[](name)
24
20
  raise IndexError, "No such property name: #{name}" unless @@properties.has_key?(name)
@@ -45,9 +41,6 @@ class OCI8
45
41
  raise ArgumentError, "float_conversion_type's value should be either :ruby or :oracle."
46
42
  end
47
43
  when :statement_cache_size
48
- if OCI8.oracle_client_version < OCI8::ORAVER_9_2
49
- raise RuntimeError, ":statement_cache_size is disabled on Oracle 9iR1 client."
50
- end
51
44
  val = val.to_i
52
45
  raise ArgumentError, "The property value for :statement_cache_size must not be negative." if val < 0
53
46
  when :events_mode
@@ -101,7 +94,7 @@ class OCI8
101
94
  # From ruby 1.9.2, a float value converted from Oracle number 15.7 by
102
95
  # the Oracle function OCINumberToReal() makes a string representation
103
96
  # 15.700000000000001 by Float#to_s.
104
- # See: http://rubyforge.org/forum/forum.php?thread_id=50030&forum_id=1078
97
+ # See: https://web.archive.org/web/20140521195004/https://rubyforge.org/forum/forum.php?thread_id=50030&forum_id=1078
105
98
  #
106
99
  # *Since:* 2.1.0
107
100
  #
@@ -109,7 +102,6 @@ class OCI8
109
102
  #
110
103
  # The statement cache size per each session. The default size is 0, which
111
104
  # means no statement cache, since 2.1.2. It was 20 in 2.1.1.
112
- # This feature is available on Oracle 9iR2 or later.
113
105
  # See: http://docs.oracle.com/cd/E11882_01/appdev.112/e10646/oci09adv.htm#i471377
114
106
  #
115
107
  # *Since:* 2.1.1
@@ -0,0 +1,3 @@
1
+ class OCI8
2
+ VERSION = "2.2.0"
3
+ end
Binary file
Binary file
Binary file
@@ -14,13 +14,23 @@ else
14
14
  gem_platform = Gem::Platform::RUBY
15
15
  end
16
16
 
17
+ if defined? OCI8
18
+ oci8_version = OCI8::VERSION
19
+ else
20
+ # Load oci8/version.rb temporarily and delete OCI8.
21
+ # Some 'bundler' tasks load this file before 'require "oci8"'
22
+ # and fail with 'TypeError: superclass mismatch for class OCI8.'
23
+ Kernel.load File.dirname(__FILE__) + '/lib/oci8/version.rb'
24
+ oci8_version = OCI8::VERSION
25
+ Object.send(:remove_const, :OCI8)
26
+ end
27
+
17
28
  spec = Gem::Specification.new do |s|
18
29
  s.name = 'ruby-oci8'
19
- s.version = File.read('VERSION').strip
30
+ s.version = oci8_version
20
31
  s.summary = 'Ruby interface for Oracle using OCI8 API'
21
32
  s.email = 'kubo@jiubao.org'
22
33
  s.homepage = 'https://github.com/kubo/ruby-oci8/'
23
- s.rubyforge_project = 'ruby-oci8'
24
34
  s.description = <<EOS
25
35
  ruby-oci8 is a ruby interface for Oracle using OCI8 API. It is available with Oracle8i, Oracle9i, Oracle10g, Oracle11g and Oracle Instant Client.
26
36
  EOS