ruby-oci8 2.2.6.1 → 2.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/test_break.rb CHANGED
@@ -22,9 +22,8 @@ class TestBreak < Minitest::Test
22
22
  @@server_is_runing_on_windows = nil
23
23
  def server_is_runing_on_windows?
24
24
  if @@server_is_runing_on_windows.nil?
25
- @@server_is_runing_on_windows = false
26
- @conn.exec('select banner from v$version') do |row|
27
- @@server_is_runing_on_windows = true if row[0].include? 'Windows'
25
+ @conn.exec('select dbms_utility.port_string from dual') do |row|
26
+ @@server_is_runing_on_windows = row[0].include? '/WIN'
28
27
  end
29
28
  end
30
29
  @@server_is_runing_on_windows
@@ -63,7 +62,7 @@ class TestBreak < Minitest::Test
63
62
  expect = []
64
63
  expect[PLSQL_DONE] = TIME_IN_PLSQL
65
64
  expect[OCIBREAK] = "Invalid status"
66
- if defined? Rubinius and Rubinius::VERSION >= "2.0"
65
+ if (defined? Rubinius and Rubinius::VERSION >= "2.0") || (defined? RUBY_ENGINE and RUBY_ENGINE == "truffleruby")
67
66
  # Rubinius 2.0.0.
68
67
  # DBMS_LOCK.SLEEP blocks ruby threads which try to call C-API.
69
68
  expect[SEND_BREAK] = TIME_TO_BREAK
@@ -100,6 +99,11 @@ class TestBreak < Minitest::Test
100
99
  def test_timeout
101
100
  @conn.non_blocking = true
102
101
  start_time = Time.now
102
+ if server_is_runing_on_windows?
103
+ end_time = start_time + 5
104
+ else
105
+ end_time = start_time + 1
106
+ end
103
107
 
104
108
  if defined? Rubinius and Rubinius::VERSION < "2.0"
105
109
  # Rubinius 1.2.4
@@ -113,12 +117,8 @@ class TestBreak < Minitest::Test
113
117
  @conn.exec("BEGIN DBMS_LOCK.SLEEP(5); END;")
114
118
  end
115
119
  end
116
- if server_is_runing_on_windows?
117
- end_time = start_time + 5
118
- else
119
- end_time = start_time + 1
120
- end
121
120
  assert_in_delta(Time.now, end_time, 1)
121
+ sleep(0.01) # for truffleruby. Is truffleruby too fast?
122
122
  @conn.exec("BEGIN NULL; END;")
123
123
  assert_in_delta(Time.now, end_time, 1)
124
124
  end
@@ -1,6 +1,5 @@
1
1
  require 'oci8'
2
2
  require File.dirname(__FILE__) + '/config'
3
- require 'scanf'
4
3
 
5
4
  class TestDateTime < Minitest::Test
6
5
 
@@ -28,6 +27,12 @@ class TestDateTime < Minitest::Test
28
27
  convert_to_datetime($1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i, subsec, $8)
29
28
  end
30
29
 
30
+ # 'YYYY-MM-DD HH24:MI:SS' or 'YYYY-MM-DD HH24:MI:SS.FF6' to array
31
+ def string_to_array(str)
32
+ /(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)(?:\.(\d+))?/ =~ str
33
+ [$1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i, $7 ? $7.to_i / 1000 : 0]
34
+ end
35
+
31
36
  def setup
32
37
  @conn = get_oci8_connection
33
38
  end
@@ -43,7 +48,7 @@ class TestDateTime < Minitest::Test
43
48
  @conn.exec(<<-EOS) do |row|
44
49
  SELECT TO_DATE('#{date}', 'YYYY-MM-DD HH24:MI:SS') FROM dual
45
50
  EOS
46
- assert_equal(Time.local(*date.scanf("%d-%d-%d %d:%d:%d.%06d")), row[0])
51
+ assert_equal(Time.local(*string_to_array(date)), row[0])
47
52
  end
48
53
  end
49
54
  end
@@ -94,7 +99,7 @@ EOS
94
99
  @conn.exec(<<-EOS) do |row|
95
100
  SELECT TO_TIMESTAMP('#{date}', 'YYYY-MM-DD HH24:MI:SS.FF') FROM dual
96
101
  EOS
97
- assert_equal(Time.local(*date.scanf("%d-%d-%d %d:%d:%d.%06d")), row[0])
102
+ assert_equal(Time.local(*string_to_array(date)), row[0])
98
103
  end
99
104
  end
100
105
  end
data/test/test_oci8.rb CHANGED
@@ -25,53 +25,142 @@ EOS
25
25
  drop_table('test_rename_table')
26
26
  end
27
27
 
28
- # USE_DYNAMIC_FETCH doesn't work well...
29
- # This test is disabled.
30
- def _test_long_type
31
- drop_table('test_table')
32
- @conn.exec('CREATE TABLE test_table (id number(38), lng long)')
33
- test_data1 = 'a' * 70000
34
- test_data2 = 'b' * 3000
35
- test_data3 = nil
36
- test_data4 = 'c' * 70000
37
- @conn.exec('insert into test_table values (:1, :2)', 1, test_data1)
38
- @conn.exec('insert into test_table values (:1, :2)', 2, [test_data2, :long])
39
- @conn.exec('insert into test_table values (:1, :2)', 3, [nil, :long])
40
- @conn.exec('insert into test_table values (:1, :2)', 4, [test_data4, :long])
41
-
42
- [8000, 65535, 65536, 80000].each do |read_len|
43
- @conn.long_read_len = read_len
44
- cursor = @conn.parse('SELECT lng from test_table order by id')
45
- cursor.exec
46
- assert_equal(test_data1, cursor.fetch[0])
47
- assert_equal(test_data2, cursor.fetch[0])
48
- assert_equal(test_data3, cursor.fetch[0])
49
- assert_equal(test_data4, cursor.fetch[0])
50
- cursor.close
28
+ # Set `OCI8::BindType::Base.initial_chunk_size = 5` to
29
+ # use the following test data.
30
+ LONG_TEST_DATA = [
31
+ # initial chunk size: 5 (total buffer size: 5)
32
+ 'a' * 4, 'b' * 5, 'c' * 6, 'd' * 5, 'e' * 4,
33
+ # second chunk size: 10 (total buffer size: 15)
34
+ 'f' * 14, 'g' * 15, 'h' * 16, 'i' * 15, 'j' * 14,
35
+ # third chunk size: 20 (total buffer size: 35)
36
+ 'k' * 34, 'l' * 35, 'm' * 36, 'n' * 35, 'o' * 34,
37
+ # use data around initial chunk size again
38
+ 'p' * 4, 'q' * 5, 'r' * 6, 's' * 5, 't' * 4,
39
+ # special data
40
+ '', nil,
41
+ ]
42
+
43
+ def test_long_type
44
+ clob_bind_type = OCI8::BindType::Mapping[:clob]
45
+ blob_bind_type = OCI8::BindType::Mapping[:blob]
46
+ initial_cunk_size = OCI8::BindType::Base.initial_chunk_size
47
+ begin
48
+ OCI8::BindType::Base.initial_chunk_size = 5
49
+ @conn.prefetch_rows = LONG_TEST_DATA.size / 3
50
+ drop_table('test_table')
51
+ ascii_enc = Encoding.find('US-ASCII')
52
+ 0.upto(1) do |i|
53
+ if i == 0
54
+ @conn.exec("CREATE TABLE test_table (id number(38), long_column long, clob_column clob)")
55
+ cursor = @conn.parse('insert into test_table values (:1, :2, :3)')
56
+ cursor.bind_param(1, nil, Integer)
57
+ cursor.bind_param(2, nil, :long)
58
+ cursor.bind_param(3, nil, :clob)
59
+ lob = OCI8::CLOB.new(@conn, '')
60
+ enc = Encoding.default_internal || OCI8.encoding
61
+ else
62
+ @conn.exec("CREATE TABLE test_table (id number(38), long_raw_column long raw, blob_column blob)")
63
+ cursor = @conn.parse('insert into test_table values (:1, :2, :3)')
64
+ cursor.bind_param(1, nil, Integer)
65
+ cursor.bind_param(2, nil, :long_raw)
66
+ cursor.bind_param(3, nil, :blob)
67
+ lob = OCI8::BLOB.new(@conn, '')
68
+ enc = Encoding.find('ASCII-8BIT')
69
+ end
70
+
71
+ LONG_TEST_DATA.each_with_index do |data, index|
72
+ cursor[1] = index
73
+ cursor[2] = data
74
+ if data.nil?
75
+ cursor[3] = nil
76
+ else
77
+ lob.rewind
78
+ lob.write(data)
79
+ lob.size = data.size
80
+ cursor[3] = lob
81
+ end
82
+ cursor.exec
83
+ end
84
+ cursor.close
85
+
86
+ cursor = @conn.parse('SELECT * from test_table order by id')
87
+ cursor.exec
88
+ LONG_TEST_DATA.each_with_index do |data, index|
89
+ row = cursor.fetch
90
+ assert_equal(index, row[0])
91
+ if data.nil?
92
+ assert_nil(row[1])
93
+ assert_nil(row[2])
94
+ elsif data.empty?
95
+ # '' is inserted to the long or long raw column as null.
96
+ assert_nil(row[1])
97
+ # '' is inserted to the clob or blob column as an empty clob.
98
+ # It is fetched as '' when the data is read using a LOB locator.
99
+ assert_equal(data, clob_data = row[2].read)
100
+ assert_equal(ascii_enc, clob_data.encoding)
101
+ else
102
+ assert_equal(data, row[1])
103
+ assert_equal(data, clob_data = row[2].read)
104
+ assert_equal(enc, row[1].encoding)
105
+ assert_equal(enc, clob_data.encoding)
106
+ end
107
+ end
108
+ assert_nil(cursor.fetch)
109
+ cursor.close
110
+
111
+ begin
112
+ OCI8::BindType::Mapping[:clob] = OCI8::BindType::Long
113
+ OCI8::BindType::Mapping[:blob] = OCI8::BindType::LongRaw
114
+ cursor = @conn.parse('SELECT * from test_table order by id')
115
+ cursor.exec
116
+ LONG_TEST_DATA.each_with_index do |data, index|
117
+ row = cursor.fetch
118
+ assert_equal(index, row[0])
119
+ if data.nil?
120
+ assert_nil(row[1])
121
+ assert_nil(row[2])
122
+ elsif data.empty?
123
+ # '' is inserted to the long or long raw column as null.
124
+ assert_nil(row[1])
125
+ # '' is inserted to the clob or blob column as an empty clob.
126
+ # However it is fetched as nil.
127
+ assert_nil(row[2])
128
+ else
129
+ assert_equal(data, row[1])
130
+ assert_equal(data, row[2])
131
+ assert_equal(enc, row[1].encoding)
132
+ assert_equal(enc, row[2].encoding)
133
+ end
134
+ end
135
+ assert_nil(cursor.fetch)
136
+ cursor.close
137
+ ensure
138
+ OCI8::BindType::Mapping[:clob] = clob_bind_type
139
+ OCI8::BindType::Mapping[:blob] = blob_bind_type
140
+ end
141
+ drop_table('test_table')
142
+ end
143
+ ensure
144
+ OCI8::BindType::Base.initial_chunk_size = initial_cunk_size
51
145
  end
52
146
  drop_table('test_table')
53
147
  end
54
148
 
55
- def test_long_type
56
- @conn.long_read_len = 80000
57
- drop_table('test_table')
58
- @conn.exec('CREATE TABLE test_table (id number(38), lng long)')
59
- test_data1 = 'a' * 70000
60
- test_data2 = 'b' * 3000
61
- test_data4 = 'c' * 70000
62
- @conn.exec('insert into test_table values (:1, :2)', 1, test_data1)
63
- @conn.exec('insert into test_table values (:1, :2)', 2, [test_data2, :long])
64
- @conn.exec('insert into test_table values (:1, :2)', 3, [nil, :long])
65
- @conn.exec('insert into test_table values (:1, :2)', 4, [test_data4, :long])
66
-
67
- cursor = @conn.parse('SELECT lng from test_table order by id')
68
- cursor.exec
69
- assert_equal(test_data1, cursor.fetch[0])
70
- assert_equal(test_data2, cursor.fetch[0])
71
- assert_nil(cursor.fetch[0])
72
- assert_equal(test_data4, cursor.fetch[0])
73
- cursor.close
74
- drop_table('test_table')
149
+ def test_bind_long_data
150
+ initial_cunk_size = OCI8::BindType::Base.initial_chunk_size
151
+ begin
152
+ OCI8::BindType::Base.initial_chunk_size = 5
153
+ cursor = @conn.parse("begin :1 := '<' || :2 || '>'; end;")
154
+ cursor.bind_param(1, nil, :long)
155
+ cursor.bind_param(2, nil, :long)
156
+ (LONG_TEST_DATA + ['z' * 4000]).each do |data|
157
+ cursor[2] = data
158
+ cursor.exec
159
+ assert_equal("<#{data}>", cursor[1])
160
+ end
161
+ ensure
162
+ OCI8::BindType::Base.initial_chunk_size = initial_cunk_size
163
+ end
75
164
  end
76
165
 
77
166
  def test_select
@@ -450,6 +539,7 @@ EOS
450
539
  assert_nil(@conn.last_error)
451
540
  @conn.last_error = 'dummy'
452
541
  cursor = @conn.parse('select col1, max(col2) from (select 1 as col1, null as col2 from dual) group by col1')
542
+ cursor.prefetch_rows = 1
453
543
  assert_nil(@conn.last_error)
454
544
 
455
545
  # When an OCI function returns OCI_SUCCESS_WITH_INFO, OCI8#last_error is set.
@@ -510,4 +600,25 @@ EOS
510
600
  end
511
601
  assert_equal(ver, @conn.oracle_server_version.to_s)
512
602
  end
603
+
604
+ def test_array_fetch
605
+ drop_table('test_table')
606
+ @conn.exec("CREATE TABLE test_table (id number, val clob)")
607
+ cursor = @conn.parse("INSERT INTO test_table VALUES (:1, :2)")
608
+ 1.upto(10) do |i|
609
+ cursor.exec(i, ('a'.ord + i).chr * i)
610
+ end
611
+ cursor.close
612
+ cursor = @conn.parse("select * from test_table where id <= :1 order by id")
613
+ cursor.prefetch_rows = 4
614
+ [1, 6, 2, 7, 3, 8, 4, 9, 5, 10].each do |i|
615
+ cursor.exec(i)
616
+ 1.upto(i) do |j|
617
+ row = cursor.fetch
618
+ assert_equal(j, row[0])
619
+ assert_equal(('a'.ord + j).chr * j, row[1].read)
620
+ end
621
+ assert_nil(cursor.fetch)
622
+ end
623
+ end
513
624
  end # TestOCI8
@@ -215,9 +215,15 @@ EOS
215
215
  end
216
216
 
217
217
  def test_yaml
218
+ # Use the permitted_classes keyword parameter if it is supported by YAML.load
219
+ keyword_params = if YAML.method(:load).parameters.any? { |key, value| value == :permitted_symbols }
220
+ {permitted_classes: [OraNumber]}
221
+ else
222
+ {}
223
+ end
218
224
  (LARGE_RANGE_VALUES + ['~', '-~']).each do |x|
219
225
  n = OraNumber.new(x)
220
- assert_equal(n, YAML.load(YAML.dump(n)))
226
+ assert_equal(n, YAML.load(YAML.dump(n), **keyword_params))
221
227
  end
222
228
  end
223
229
 
metadata CHANGED
@@ -1,36 +1,27 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ruby-oci8
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 2
7
- - 2
8
- - 6
9
- - 1
10
- version: 2.2.6.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.2.10
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Kubo Takehiro
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2018-09-16 00:00:00 +09:00
19
- default_executable:
11
+ date: 2022-01-12 00:00:00.000000000 Z
20
12
  dependencies: []
13
+ description: 'ruby-oci8 is a ruby interface for Oracle using OCI8 API. It is available
14
+ with Oracle 10g or later including Oracle Instant Client.
21
15
 
22
- description: |
23
- ruby-oci8 is a ruby interface for Oracle using OCI8 API. It is available with Oracle 10g or later including Oracle Instant Client.
24
-
16
+ '
25
17
  email: kubo@jiubao.org
26
18
  executables: []
27
-
28
- extensions:
19
+ extensions:
29
20
  - ext/oci8/extconf.rb
30
- extra_rdoc_files:
21
+ extra_rdoc_files:
31
22
  - README.md
32
- files:
33
- - .yardopts
23
+ files:
24
+ - ".yardopts"
34
25
  - COPYING
35
26
  - COPYING_old
36
27
  - ChangeLog
@@ -38,10 +29,6 @@ files:
38
29
  - NEWS
39
30
  - README.md
40
31
  - dist-files
41
- - metaconfig
42
- - pre-distclean.rb
43
- - ruby-oci8.gemspec
44
- - setup.rb
45
32
  - docs/bind-array-to-in_cond.md
46
33
  - docs/conflicts-local-connections-and-processes.md
47
34
  - docs/hanging-after-inactivity.md
@@ -51,7 +38,6 @@ files:
51
38
  - docs/install-on-osx.md
52
39
  - docs/ldap-auth-and-function-interposition.md
53
40
  - docs/number-type-mapping.md
54
- - docs/osx-install-dev-tools.png
55
41
  - docs/platform-specific-issues.md
56
42
  - docs/report-installation-issue.md
57
43
  - docs/timeout-parameters.md
@@ -93,8 +79,8 @@ files:
93
79
  - ext/oci8/util.c
94
80
  - ext/oci8/win32.c
95
81
  - lib/.document
96
- - lib/oci8.rb
97
82
  - lib/dbd/OCI8.rb
83
+ - lib/oci8.rb
98
84
  - lib/oci8/.document
99
85
  - lib/oci8/bindtype.rb
100
86
  - lib/oci8/check_load_error.rb
@@ -112,7 +98,11 @@ files:
112
98
  - lib/oci8/properties.rb
113
99
  - lib/oci8/version.rb
114
100
  - lib/ruby-oci8.rb
115
- - test/README
101
+ - metaconfig
102
+ - pre-distclean.rb
103
+ - ruby-oci8.gemspec
104
+ - setup.rb
105
+ - test/README.md
116
106
  - test/config.rb
117
107
  - test/setup_test_object.sql
118
108
  - test/setup_test_package.sql
@@ -121,18 +111,18 @@ files:
121
111
  - test/test_array_dml.rb
122
112
  - test/test_bind_array.rb
123
113
  - test/test_bind_boolean.rb
114
+ - test/test_bind_integer.rb
124
115
  - test/test_bind_raw.rb
125
116
  - test/test_bind_string.rb
126
117
  - test/test_bind_time.rb
127
- - test/test_bind_integer.rb
128
118
  - test/test_break.rb
129
119
  - test/test_clob.rb
130
120
  - test/test_connection_pool.rb
131
121
  - test/test_connstr.rb
132
- - test/test_encoding.rb
133
122
  - test/test_datetime.rb
134
123
  - test/test_dbi.rb
135
124
  - test/test_dbi_clob.rb
125
+ - test/test_encoding.rb
136
126
  - test/test_error.rb
137
127
  - test/test_metadata.rb
138
128
  - test/test_object.rb
@@ -143,40 +133,28 @@ files:
143
133
  - test/test_package_type.rb
144
134
  - test/test_properties.rb
145
135
  - test/test_rowid.rb
146
- has_rdoc: true
147
136
  homepage: http://www.rubydoc.info/github/kubo/ruby-oci8
148
- licenses:
137
+ licenses:
149
138
  - BSD-2-Clause
139
+ metadata: {}
150
140
  post_install_message:
151
141
  rdoc_options: []
152
-
153
- require_paths:
142
+ require_paths:
154
143
  - lib
155
- - ext/oci8
156
- required_ruby_version: !ruby/object:Gem::Requirement
157
- none: false
158
- requirements:
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
159
146
  - - ">="
160
- - !ruby/object:Gem::Version
161
- segments:
162
- - 1
163
- - 9
164
- - 1
147
+ - !ruby/object:Gem::Version
165
148
  version: 1.9.1
166
- required_rubygems_version: !ruby/object:Gem::Requirement
167
- none: false
168
- requirements:
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
169
151
  - - ">="
170
- - !ruby/object:Gem::Version
171
- segments:
172
- - 0
173
- version: "0"
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
174
154
  requirements: []
175
-
176
- rubyforge_project:
177
- rubygems_version: 1.3.7
155
+ rubygems_version: 3.1.2
178
156
  signing_key:
179
- specification_version: 3
157
+ specification_version: 4
180
158
  summary: Ruby interface for Oracle using OCI8 API
181
- test_files:
159
+ test_files:
182
160
  - test/test_all.rb
Binary file
data/test/README DELETED
@@ -1,42 +0,0 @@
1
- Before runing unit test:
2
-
3
- 1. connect to Oracle as system:
4
-
5
- $ sqlplus system/<password_of_system>
6
-
7
- 2. create user ruby:
8
-
9
- SQL> CREATE USER ruby IDENTIFIED BY oci8;
10
-
11
- or
12
-
13
- SQL> CREATE USER ruby IDENTIFIED BY oci8
14
- 2 DEFAULT TABLESPACE users TEMPORARY TABLESPACE temp;
15
-
16
- 3. grant the privilege to connect and execute.
17
-
18
- SQL> GRANT connect, resource, create view TO ruby;
19
-
20
- 4. connect to Oracle as sys
21
-
22
- $ sqlplus 'sys/<password_of_sys> as sysdba'
23
-
24
- 5. grant privileges
25
-
26
- SQL> GRANT EXECUTE ON dbms_lock TO ruby;
27
- SQL> GRANT CREATE VIEW TO ruby;
28
-
29
- 6. connect as ruby user.
30
-
31
- $ sqlplus ruby/oci8
32
-
33
- 7. Create object types
34
-
35
- SQL> @test/setup_test_object.sql
36
-
37
- 8. change $dbname if the database
38
-
39
- Then you can run:
40
- $ make check
41
- or
42
- $ nmake check (If your compiler is MS Visual C++.)