ruby-oci8 2.2.10-x64-mingw-ucrt
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +14 -0
- data/COPYING +30 -0
- data/COPYING_old +64 -0
- data/ChangeLog +3826 -0
- data/Makefile +92 -0
- data/NEWS +1209 -0
- data/README.md +66 -0
- data/dist-files +112 -0
- data/docs/bind-array-to-in_cond.md +38 -0
- data/docs/conflicts-local-connections-and-processes.md +98 -0
- data/docs/hanging-after-inactivity.md +63 -0
- data/docs/install-binary-package.md +44 -0
- data/docs/install-full-client.md +111 -0
- data/docs/install-instant-client.md +194 -0
- data/docs/install-on-osx.md +46 -0
- data/docs/ldap-auth-and-function-interposition.md +123 -0
- data/docs/number-type-mapping.md +79 -0
- data/docs/platform-specific-issues.md +164 -0
- data/docs/report-installation-issue.md +50 -0
- data/docs/timeout-parameters.md +94 -0
- data/lib/.document +1 -0
- data/lib/dbd/OCI8.rb +591 -0
- data/lib/oci8/.document +8 -0
- data/lib/oci8/bindtype.rb +333 -0
- data/lib/oci8/check_load_error.rb +146 -0
- data/lib/oci8/compat.rb +117 -0
- data/lib/oci8/connection_pool.rb +179 -0
- data/lib/oci8/cursor.rb +605 -0
- data/lib/oci8/datetime.rb +605 -0
- data/lib/oci8/encoding-init.rb +45 -0
- data/lib/oci8/encoding.yml +537 -0
- data/lib/oci8/metadata.rb +2148 -0
- data/lib/oci8/object.rb +641 -0
- data/lib/oci8/oci8.rb +756 -0
- data/lib/oci8/ocihandle.rb +591 -0
- data/lib/oci8/oracle_version.rb +153 -0
- data/lib/oci8/properties.rb +196 -0
- data/lib/oci8/version.rb +3 -0
- data/lib/oci8.rb +190 -0
- data/lib/oci8lib_310.so +0 -0
- data/lib/ruby-oci8.rb +1 -0
- data/metaconfig +142 -0
- data/pre-distclean.rb +7 -0
- data/ruby-oci8.gemspec +85 -0
- data/setup.rb +1342 -0
- data/test/README.md +37 -0
- data/test/config.rb +201 -0
- data/test/setup_test_object.sql +199 -0
- data/test/setup_test_package.sql +59 -0
- data/test/test_all.rb +56 -0
- data/test/test_appinfo.rb +62 -0
- data/test/test_array_dml.rb +332 -0
- data/test/test_bind_array.rb +70 -0
- data/test/test_bind_boolean.rb +99 -0
- data/test/test_bind_integer.rb +47 -0
- data/test/test_bind_raw.rb +45 -0
- data/test/test_bind_string.rb +105 -0
- data/test/test_bind_time.rb +177 -0
- data/test/test_break.rb +125 -0
- data/test/test_clob.rb +85 -0
- data/test/test_connection_pool.rb +124 -0
- data/test/test_connstr.rb +220 -0
- data/test/test_datetime.rb +585 -0
- data/test/test_dbi.rb +365 -0
- data/test/test_dbi_clob.rb +53 -0
- data/test/test_encoding.rb +103 -0
- data/test/test_error.rb +87 -0
- data/test/test_metadata.rb +2674 -0
- data/test/test_object.rb +546 -0
- data/test/test_oci8.rb +624 -0
- data/test/test_oracle_version.rb +68 -0
- data/test/test_oradate.rb +255 -0
- data/test/test_oranumber.rb +792 -0
- data/test/test_package_type.rb +981 -0
- data/test/test_properties.rb +17 -0
- data/test/test_rowid.rb +32 -0
- metadata +123 -0
data/test/test_oci8.rb
ADDED
@@ -0,0 +1,624 @@
|
|
1
|
+
require 'oci8'
|
2
|
+
require File.dirname(__FILE__) + '/config'
|
3
|
+
require 'bigdecimal'
|
4
|
+
require 'rational'
|
5
|
+
|
6
|
+
class TestOCI8 < Minitest::Test
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@conn = get_oci8_connection
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
@conn.logoff
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_rename
|
17
|
+
drop_table('test_table')
|
18
|
+
drop_table('test_rename_table')
|
19
|
+
sql = <<-EOS
|
20
|
+
CREATE TABLE test_rename_table
|
21
|
+
(C CHAR(10) NOT NULL)
|
22
|
+
EOS
|
23
|
+
@conn.exec(sql)
|
24
|
+
@conn.exec("RENAME test_rename_table TO test_table")
|
25
|
+
drop_table('test_rename_table')
|
26
|
+
end
|
27
|
+
|
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
|
145
|
+
end
|
146
|
+
drop_table('test_table')
|
147
|
+
end
|
148
|
+
|
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
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_select
|
167
|
+
drop_table('test_table')
|
168
|
+
sql = <<-EOS
|
169
|
+
CREATE TABLE test_table
|
170
|
+
(C CHAR(10) NOT NULL,
|
171
|
+
V VARCHAR2(20),
|
172
|
+
N NUMBER(10, 2),
|
173
|
+
D1 DATE, D2 DATE, D3 DATE, D4 DATE,
|
174
|
+
INT NUMBER(30), BIGNUM NUMBER(30))
|
175
|
+
STORAGE (
|
176
|
+
INITIAL 4k
|
177
|
+
NEXT 4k
|
178
|
+
MINEXTENTS 1
|
179
|
+
MAXEXTENTS UNLIMITED
|
180
|
+
PCTINCREASE 0)
|
181
|
+
EOS
|
182
|
+
@conn.exec(sql)
|
183
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:C, :V, :N, :D1, :D2, :D3, :D4, :INT, :BIGNUM)")
|
184
|
+
1.upto(10) do |i|
|
185
|
+
if i == 1
|
186
|
+
dt = [nil, OraDate]
|
187
|
+
else
|
188
|
+
dt = OraDate.new(2000 + i, i % 2 == 0 ? 7 : 1, 3, 23, 59, 59)
|
189
|
+
end
|
190
|
+
cursor.exec(format("%10d", i * 10), i.to_s, i, dt, dt, dt, dt, i * 11111111111, i * 10000000000)
|
191
|
+
end
|
192
|
+
cursor.close
|
193
|
+
cursor = @conn.parse("SELECT * FROM test_table ORDER BY c")
|
194
|
+
cursor.define(5, Time) # define 5th column as Time
|
195
|
+
cursor.define(6, Date) # define 6th column as Date
|
196
|
+
cursor.define(7, DateTime) # define 7th column as DateTime
|
197
|
+
cursor.define(8, Integer) # define 8th column as Integer
|
198
|
+
cursor.define(9, Bignum) # define 9th column as Bignum
|
199
|
+
cursor.exec
|
200
|
+
assert_equal(["C", "V", "N", "D1", "D2", "D3", "D4", "INT", "BIGNUM"], cursor.get_col_names)
|
201
|
+
1.upto(10) do |i|
|
202
|
+
rv = cursor.fetch
|
203
|
+
assert_equal(format("%10d", i * 10), rv[0])
|
204
|
+
assert_equal(i.to_s, rv[1])
|
205
|
+
assert_equal(i, rv[2])
|
206
|
+
if i == 1
|
207
|
+
assert_nil(rv[3])
|
208
|
+
assert_nil(rv[4])
|
209
|
+
assert_nil(rv[5])
|
210
|
+
assert_nil(rv[6])
|
211
|
+
else
|
212
|
+
month = i % 2 == 0 ? 7 : 1
|
213
|
+
tm = Time.local(2000 + i, month, 3, 23, 59, 59)
|
214
|
+
dt = Date.civil(2000 + i, month, 3)
|
215
|
+
dttm = DateTime.civil(2000 + i, month, 3, 23, 59, 59, tm.utc_offset.to_r/86400)
|
216
|
+
assert_equal(tm, rv[3])
|
217
|
+
assert_equal(tm, rv[4])
|
218
|
+
assert_equal(dt, rv[5])
|
219
|
+
assert_equal(dttm, rv[6])
|
220
|
+
end
|
221
|
+
assert_equal(i * 11111111111, rv[7])
|
222
|
+
assert_equal(i * 10000000000, rv[8])
|
223
|
+
end
|
224
|
+
assert_nil(cursor.fetch)
|
225
|
+
|
226
|
+
# fetch_hash with block
|
227
|
+
cursor.exec
|
228
|
+
i = 1
|
229
|
+
cursor.fetch_hash do |row|
|
230
|
+
assert_equal(format("%10d", i * 10), row['C'])
|
231
|
+
assert_equal(i.to_s, row['V'])
|
232
|
+
assert_equal(i, row['N'])
|
233
|
+
if i == 1
|
234
|
+
assert_nil(row['D1'])
|
235
|
+
assert_nil(row['D2'])
|
236
|
+
assert_nil(row['D3'])
|
237
|
+
assert_nil(row['D4'])
|
238
|
+
else
|
239
|
+
month = i % 2 == 0 ? 7 : 1
|
240
|
+
tm = Time.local(2000 + i, month, 3, 23, 59, 59)
|
241
|
+
dt = Date.civil(2000 + i, month, 3)
|
242
|
+
dttm = DateTime.civil(2000 + i, month, 3, 23, 59, 59, tm.utc_offset.to_r/86400)
|
243
|
+
assert_equal(tm, row['D1'])
|
244
|
+
assert_equal(tm, row['D2'])
|
245
|
+
assert_equal(dt, row['D3'])
|
246
|
+
assert_equal(dttm, row['D4'])
|
247
|
+
end
|
248
|
+
assert_equal(i * 11111111111, row['INT'])
|
249
|
+
assert_equal(i * 10000000000, row['BIGNUM'])
|
250
|
+
i += 1
|
251
|
+
end
|
252
|
+
assert_equal(11, i)
|
253
|
+
|
254
|
+
cursor.close
|
255
|
+
drop_table('test_table')
|
256
|
+
end
|
257
|
+
|
258
|
+
def test_bind_cursor
|
259
|
+
# FIXME: check again after upgrading Oracle 9.2 to 9.2.0.4.
|
260
|
+
return if $oracle_version < OCI8::ORAVER_10_1
|
261
|
+
|
262
|
+
drop_table('test_table')
|
263
|
+
sql = <<-EOS
|
264
|
+
CREATE TABLE test_table
|
265
|
+
(C CHAR(10) NOT NULL,
|
266
|
+
V VARCHAR2(20),
|
267
|
+
N NUMBER(10, 2),
|
268
|
+
D1 DATE, D2 DATE, D3 DATE,
|
269
|
+
INT NUMBER(30), BIGNUM NUMBER(30))
|
270
|
+
STORAGE (
|
271
|
+
INITIAL 4k
|
272
|
+
NEXT 4k
|
273
|
+
MINEXTENTS 1
|
274
|
+
MAXEXTENTS UNLIMITED
|
275
|
+
PCTINCREASE 0)
|
276
|
+
EOS
|
277
|
+
@conn.exec(sql)
|
278
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:C, :V, :N, :D1, :D2, :D3, :INT, :BIGNUM)")
|
279
|
+
1.upto(10) do |i|
|
280
|
+
if i == 1
|
281
|
+
dt = [nil, OraDate]
|
282
|
+
else
|
283
|
+
dt = OraDate.new(2000 + i, 8, 3, 23, 59, 59)
|
284
|
+
end
|
285
|
+
cursor.exec(format("%10d", i * 10), i.to_s, i, dt, dt, dt, i, i)
|
286
|
+
end
|
287
|
+
cursor.close
|
288
|
+
plsql = @conn.parse("BEGIN OPEN :cursor FOR SELECT * FROM test_table ORDER BY c; END;")
|
289
|
+
plsql.bind_param(':cursor', nil, OCI8::Cursor)
|
290
|
+
plsql.exec
|
291
|
+
cursor = plsql[':cursor']
|
292
|
+
cursor.define(5, DateTime) # define 5th column as DateTime
|
293
|
+
cursor.define(6, Date) # define 6th column as Date
|
294
|
+
cursor.define(7, Integer) # define 7th column as Integer
|
295
|
+
cursor.define(8, Bignum) # define 8th column as Integer
|
296
|
+
assert_equal(["C", "V", "N", "D1", "D2", "D3", "INT", "BIGNUM"], cursor.get_col_names)
|
297
|
+
1.upto(10) do |i|
|
298
|
+
rv = cursor.fetch
|
299
|
+
assert_equal(format("%10d", i * 10), rv[0])
|
300
|
+
assert_equal(i.to_s, rv[1])
|
301
|
+
assert_equal(i, rv[2])
|
302
|
+
if i == 1
|
303
|
+
assert_nil(rv[3])
|
304
|
+
assert_nil(rv[4])
|
305
|
+
assert_nil(rv[5])
|
306
|
+
else
|
307
|
+
tm = Time.local(2000 + i, 8, 3, 23, 59, 59)
|
308
|
+
dttm = DateTime.civil(2000 + i, 8, 3, 23, 59, 59, tm.utc_offset.to_r/86400)
|
309
|
+
dt = Date.civil(2000 + i, 8, 3)
|
310
|
+
assert_equal(tm, rv[3])
|
311
|
+
assert_equal(dttm, rv[4])
|
312
|
+
assert_equal(dt, rv[5])
|
313
|
+
end
|
314
|
+
assert_equal(i, rv[6])
|
315
|
+
assert_equal(i, rv[7])
|
316
|
+
end
|
317
|
+
assert_nil(cursor.fetch)
|
318
|
+
cursor.close
|
319
|
+
drop_table('test_table')
|
320
|
+
end
|
321
|
+
|
322
|
+
def test_cursor_in_result_set
|
323
|
+
drop_table('test_table')
|
324
|
+
sql = <<-EOS
|
325
|
+
CREATE TABLE test_table (N NUMBER(10, 2))
|
326
|
+
STORAGE (
|
327
|
+
INITIAL 4k
|
328
|
+
NEXT 4k
|
329
|
+
MINEXTENTS 1
|
330
|
+
MAXEXTENTS UNLIMITED
|
331
|
+
PCTINCREASE 0)
|
332
|
+
EOS
|
333
|
+
@conn.exec(sql)
|
334
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:1)")
|
335
|
+
1.upto(10) do |i|
|
336
|
+
cursor.exec(i)
|
337
|
+
end
|
338
|
+
cursor.close
|
339
|
+
cursor = @conn.exec(<<EOS)
|
340
|
+
select a.n, cursor (select a.n + b.n
|
341
|
+
from test_table b
|
342
|
+
order by n)
|
343
|
+
from test_table a
|
344
|
+
order by n
|
345
|
+
EOS
|
346
|
+
1.upto(10) do |i|
|
347
|
+
row = cursor.fetch
|
348
|
+
assert_equal(i, row[0])
|
349
|
+
cursor_in_result_set = row[1]
|
350
|
+
1.upto(10) do |j|
|
351
|
+
row2 = cursor_in_result_set.fetch
|
352
|
+
assert_equal(i + j, row2[0])
|
353
|
+
end
|
354
|
+
assert_nil(cursor_in_result_set.fetch) # check end of row data
|
355
|
+
cursor_in_result_set.close
|
356
|
+
end
|
357
|
+
assert_nil(cursor.fetch) # check end of row data
|
358
|
+
drop_table('test_table')
|
359
|
+
end
|
360
|
+
|
361
|
+
def test_binary_float
|
362
|
+
return if $oracle_version < OCI8::ORAVER_10_1
|
363
|
+
|
364
|
+
# Oracle 10g or upper
|
365
|
+
cursor = @conn.parse("select CAST(:1 AS BINARY_FLOAT), CAST(:2 AS BINARY_DOUBLE) from dual")
|
366
|
+
bind_val = -1.0
|
367
|
+
cursor.bind_param(1, 10.0, :binary_double)
|
368
|
+
cursor.bind_param(2, nil, :binary_double)
|
369
|
+
while bind_val < 10.0
|
370
|
+
cursor[2] = bind_val
|
371
|
+
cursor.exec
|
372
|
+
rv = cursor.fetch
|
373
|
+
assert_equal(10.0, rv[0])
|
374
|
+
assert_equal(bind_val, rv[1])
|
375
|
+
bind_val += 1.234
|
376
|
+
end
|
377
|
+
[-1.0/0.0, # -Infinite
|
378
|
+
+1.0/0.0, # +Infinite
|
379
|
+
0.0/0.0 # NaN
|
380
|
+
].each do |num|
|
381
|
+
cursor[1] = num
|
382
|
+
cursor[2] = num
|
383
|
+
cursor.exec
|
384
|
+
rv = cursor.fetch
|
385
|
+
if num.nan?
|
386
|
+
assert(rv[0].nan?)
|
387
|
+
assert(rv[1].nan?)
|
388
|
+
else
|
389
|
+
assert_equal(num, rv[0])
|
390
|
+
assert_equal(num, rv[1])
|
391
|
+
end
|
392
|
+
end
|
393
|
+
cursor.close
|
394
|
+
end
|
395
|
+
|
396
|
+
def test_clob_nclob_and_blob
|
397
|
+
return if OCI8::oracle_client_version < OCI8::ORAVER_8_1
|
398
|
+
|
399
|
+
drop_table('test_table')
|
400
|
+
sql = <<-EOS
|
401
|
+
CREATE TABLE test_table (id number(5), C CLOB, NC NCLOB, B BLOB)
|
402
|
+
STORAGE (
|
403
|
+
INITIAL 100k
|
404
|
+
NEXT 100k
|
405
|
+
MINEXTENTS 1
|
406
|
+
MAXEXTENTS UNLIMITED
|
407
|
+
PCTINCREASE 0)
|
408
|
+
EOS
|
409
|
+
@conn.exec(sql)
|
410
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:1, :2, :3, :4)")
|
411
|
+
0.upto(9) do |i|
|
412
|
+
val = case i
|
413
|
+
when 5; '' # empty string
|
414
|
+
else format('%d', i) * 4096
|
415
|
+
end
|
416
|
+
cursor.exec(i, OCI8::CLOB.new(@conn, val), OCI8::NCLOB.new(@conn, val), OCI8::BLOB.new(@conn, val))
|
417
|
+
end
|
418
|
+
cursor.close
|
419
|
+
cursor = @conn.exec("select * from test_table order by id")
|
420
|
+
0.upto(9) do |i|
|
421
|
+
rv = cursor.fetch
|
422
|
+
val = case i
|
423
|
+
when 5; '' # empty string
|
424
|
+
else format('%d', i) * 4096
|
425
|
+
end
|
426
|
+
assert_equal(i, rv[0])
|
427
|
+
assert_instance_of(OCI8::CLOB, rv[1])
|
428
|
+
assert_instance_of(OCI8::NCLOB, rv[2])
|
429
|
+
assert_instance_of(OCI8::BLOB, rv[3])
|
430
|
+
assert_equal(val, rv[1].read)
|
431
|
+
assert_equal(val.length, rv[2].size)
|
432
|
+
assert_equal(val, rv[2].read)
|
433
|
+
assert_equal(val, rv[3].read)
|
434
|
+
end
|
435
|
+
assert_nil(cursor.fetch)
|
436
|
+
cursor.close
|
437
|
+
drop_table('test_table')
|
438
|
+
end
|
439
|
+
|
440
|
+
def test_select_number
|
441
|
+
drop_table('test_table')
|
442
|
+
@conn.exec(<<EOS)
|
443
|
+
CREATE TABLE test_table (n NUMBER, n20 NUMBER(20), n14_2 NUMBER(14,2), n15_2 NUMBER(15,2), flt FLOAT)
|
444
|
+
STORAGE (
|
445
|
+
INITIAL 100k
|
446
|
+
NEXT 100k
|
447
|
+
MINEXTENTS 1
|
448
|
+
MAXEXTENTS UNLIMITED
|
449
|
+
PCTINCREASE 0)
|
450
|
+
EOS
|
451
|
+
@conn.exec(<<EOS)
|
452
|
+
INSERT INTO test_table values(12345678901234, 12345678901234567890, 123456789012.34, 1234567890123.45, 1234.5)
|
453
|
+
EOS
|
454
|
+
@conn.exec("select * from test_table") do |row|
|
455
|
+
assert_equal(row[0], 12345678901234)
|
456
|
+
assert_equal(row[1], 12345678901234567890)
|
457
|
+
assert_equal(row[2], 123456789012.34)
|
458
|
+
assert_equal(row[3], BigDecimal("1234567890123.45"))
|
459
|
+
assert_equal(row[4], 1234.5)
|
460
|
+
assert_instance_of(BigDecimal, row[0])
|
461
|
+
assert_instance_of(Bignum, row[1])
|
462
|
+
assert_instance_of(Float, row[2])
|
463
|
+
assert_instance_of(BigDecimal, row[3])
|
464
|
+
assert_instance_of(Float, row[4])
|
465
|
+
end
|
466
|
+
drop_table('test_table')
|
467
|
+
end
|
468
|
+
|
469
|
+
def test_bind_number_with_implicit_conversions
|
470
|
+
src = [1, 1.2, BigDecimal("1.2"), Rational(12, 10)]
|
471
|
+
int = [1, 1, 1, 1]
|
472
|
+
flt = [1, 1.2, 1.2, 1.2]
|
473
|
+
dec = [BigDecimal("1"), BigDecimal("1.2"), BigDecimal("1.2"), BigDecimal("1.2")]
|
474
|
+
rat = [Rational(1), Rational(12, 10), Rational(12, 10), Rational(12, 10)]
|
475
|
+
|
476
|
+
cursor = @conn.parse("begin :1 := :2; end;")
|
477
|
+
|
478
|
+
# Float
|
479
|
+
cursor.bind_param(1, nil, Float)
|
480
|
+
cursor.bind_param(2, nil, Float)
|
481
|
+
src.each_with_index do |s, idx|
|
482
|
+
cursor[2] = s
|
483
|
+
cursor.exec
|
484
|
+
assert_equal(cursor[1], flt[idx])
|
485
|
+
assert_kind_of(Float, cursor[1])
|
486
|
+
end
|
487
|
+
|
488
|
+
# Fixnum
|
489
|
+
cursor.bind_param(1, nil, Fixnum)
|
490
|
+
cursor.bind_param(2, nil, Fixnum)
|
491
|
+
src.each_with_index do |s, idx|
|
492
|
+
cursor[2] = s
|
493
|
+
cursor.exec
|
494
|
+
assert_equal(cursor[1], int[idx])
|
495
|
+
assert_kind_of(Fixnum, cursor[1])
|
496
|
+
end
|
497
|
+
|
498
|
+
# Integer
|
499
|
+
cursor.bind_param(1, nil, Integer)
|
500
|
+
cursor.bind_param(2, nil, Integer)
|
501
|
+
src.each_with_index do |s, idx|
|
502
|
+
cursor[2] = s
|
503
|
+
cursor.exec
|
504
|
+
assert_equal(cursor[1], int[idx])
|
505
|
+
assert_kind_of(Integer, cursor[1])
|
506
|
+
end
|
507
|
+
|
508
|
+
# BigDecimal
|
509
|
+
cursor.bind_param(1, nil, BigDecimal)
|
510
|
+
cursor.bind_param(2, nil, BigDecimal)
|
511
|
+
src.each_with_index do |s, idx|
|
512
|
+
cursor[2] = s
|
513
|
+
cursor.exec
|
514
|
+
assert_equal(cursor[1], dec[idx])
|
515
|
+
assert_kind_of(BigDecimal, cursor[1])
|
516
|
+
end
|
517
|
+
|
518
|
+
# Rational
|
519
|
+
cursor.bind_param(1, nil, Rational)
|
520
|
+
cursor.bind_param(2, nil, Rational)
|
521
|
+
src.each_with_index do |s, idx|
|
522
|
+
cursor[2] = s
|
523
|
+
cursor.exec
|
524
|
+
assert_equal(cursor[1], rat[idx])
|
525
|
+
assert_kind_of(Rational, cursor[1])
|
526
|
+
end
|
527
|
+
end
|
528
|
+
|
529
|
+
def test_parse_sets_query_on_cursor
|
530
|
+
statement = "select * from country where country_code = 'ja'"
|
531
|
+
cursor = @conn.parse(statement)
|
532
|
+
assert_equal(statement, cursor.statement)
|
533
|
+
end
|
534
|
+
|
535
|
+
def test_last_error
|
536
|
+
# OCI8#parse and OCI8#exec reset OCI8#last_error
|
537
|
+
@conn.last_error = 'dummy'
|
538
|
+
@conn.exec('begin null; end;')
|
539
|
+
assert_nil(@conn.last_error)
|
540
|
+
@conn.last_error = 'dummy'
|
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
|
543
|
+
assert_nil(@conn.last_error)
|
544
|
+
|
545
|
+
# When an OCI function returns OCI_SUCCESS_WITH_INFO, OCI8#last_error is set.
|
546
|
+
@conn.last_error = 'dummy'
|
547
|
+
cursor.exec
|
548
|
+
assert_equal('dummy', @conn.last_error)
|
549
|
+
cursor.fetch
|
550
|
+
assert_kind_of(OCISuccessWithInfo, @conn.last_error)
|
551
|
+
assert_equal(24347, @conn.last_error.code)
|
552
|
+
end
|
553
|
+
|
554
|
+
def test_environment_handle
|
555
|
+
# OCI_ATTR_HEAPALLOC
|
556
|
+
assert_operator(OCI8.send(:class_variable_get, :@@environment_handle).send(:attr_get_ub4, 30), :>, 0)
|
557
|
+
# OCI_ATTR_OBJECT
|
558
|
+
assert(OCI8.send(:class_variable_get, :@@environment_handle).send(:attr_get_boolean, 2))
|
559
|
+
# OCI_ATTR_SHARED_HEAPALLOC
|
560
|
+
assert_equal(0, OCI8.send(:class_variable_get, :@@environment_handle).send(:attr_get_ub4, 84))
|
561
|
+
end
|
562
|
+
|
563
|
+
def test_process_handle
|
564
|
+
# OCI_ATTR_MEMPOOL_APPNAME
|
565
|
+
assert_equal('', OCI8.send(:class_variable_get, :@@process_handle).send(:attr_get_string, 90))
|
566
|
+
# OCI_ATTR_MEMPOOL_SIZE
|
567
|
+
assert_equal(0, OCI8.send(:class_variable_get, :@@process_handle).send(:attr_get_ub4, 88))
|
568
|
+
end
|
569
|
+
|
570
|
+
def test_client_driver_name
|
571
|
+
if OCI8.oracle_client_version >= OCI8::ORAVER_11_1 and @conn.oracle_server_version >= OCI8::ORAVER_11_1
|
572
|
+
sid = @conn.select_one("select userenv('sid') from dual")[0].to_i
|
573
|
+
cursor = @conn.parse('select client_driver from v$session_connect_info where sid = :1')
|
574
|
+
cursor.exec(sid)
|
575
|
+
column_size = cursor.column_metadata[0].data_size
|
576
|
+
expected_value = case column_size
|
577
|
+
when 30 # Oracle version >= 12.1.0.2
|
578
|
+
"ruby-oci8 : #{OCI8::VERSION}"
|
579
|
+
when 9 # Oracle version < 12.1.0.2
|
580
|
+
'ruby-oci' # only the first 8 characters
|
581
|
+
else
|
582
|
+
raise "Unknown column size #{column_size}"
|
583
|
+
end
|
584
|
+
driver_name = cursor.fetch[0].strip
|
585
|
+
cursor.close
|
586
|
+
assert_equal(expected_value, driver_name)
|
587
|
+
end
|
588
|
+
end
|
589
|
+
|
590
|
+
def test_server_version
|
591
|
+
cursor = @conn.exec("select * from product_component_version where product like 'Oracle Database %'")
|
592
|
+
row = cursor.fetch_hash
|
593
|
+
cursor.close
|
594
|
+
ver = if OCI8::oracle_client_version >= OCI8::ORAVER_18
|
595
|
+
row['VERSION_FULL'] || row['VERSION']
|
596
|
+
else
|
597
|
+
# OCI8#oracle_server_version could not get infomation corresponding
|
598
|
+
# to VERSION_FULL when the Oracle client version is below 18.1.
|
599
|
+
row['VERSION']
|
600
|
+
end
|
601
|
+
assert_equal(ver, @conn.oracle_server_version.to_s)
|
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
|
624
|
+
end # TestOCI8
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'oci8'
|
2
|
+
require File.dirname(__FILE__) + '/config'
|
3
|
+
|
4
|
+
class TestOracleVersion < Minitest::Test
|
5
|
+
|
6
|
+
def test_init
|
7
|
+
oraver = OCI8::OracleVersion.new('8.1.6.2.3')
|
8
|
+
assert_equal(8, oraver.major)
|
9
|
+
assert_equal(1, oraver.minor)
|
10
|
+
assert_equal(6, oraver.update)
|
11
|
+
assert_equal(2, oraver.patch)
|
12
|
+
assert_equal(3, oraver.port_update)
|
13
|
+
|
14
|
+
oraver = OCI8::OracleVersion.new('8.1.6')
|
15
|
+
assert_equal(8, oraver.major)
|
16
|
+
assert_equal(1, oraver.minor)
|
17
|
+
assert_equal(6, oraver.update)
|
18
|
+
assert_equal(0, oraver.patch)
|
19
|
+
assert_equal(0, oraver.port_update)
|
20
|
+
|
21
|
+
oraver = OCI8::OracleVersion.new('10')
|
22
|
+
assert_equal(10, oraver.major)
|
23
|
+
assert_equal(0, oraver.minor)
|
24
|
+
assert_equal(0, oraver.update)
|
25
|
+
assert_equal(0, oraver.patch)
|
26
|
+
assert_equal(0, oraver.port_update)
|
27
|
+
|
28
|
+
oraver = OCI8::OracleVersion.new(0x08106203)
|
29
|
+
assert_equal(8, oraver.major)
|
30
|
+
assert_equal(1, oraver.minor)
|
31
|
+
assert_equal(6, oraver.update)
|
32
|
+
assert_equal(2, oraver.patch)
|
33
|
+
assert_equal(3, oraver.port_update)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_compare
|
37
|
+
oraver = OCI8::OracleVersion.new('8.1.6.2.3')
|
38
|
+
assert_operator(oraver, :==, OCI8::OracleVersion.new('8.1.6.2.3'))
|
39
|
+
assert_operator(oraver, :<, OCI8::OracleVersion.new('9.1.6.2.3'))
|
40
|
+
assert_operator(oraver, :<, OCI8::OracleVersion.new('8.2.6.2.3'))
|
41
|
+
assert_operator(oraver, :<, OCI8::OracleVersion.new('8.1.7.2.3'))
|
42
|
+
assert_operator(oraver, :<, OCI8::OracleVersion.new('8.1.6.3.3'))
|
43
|
+
assert_operator(oraver, :<, OCI8::OracleVersion.new('8.1.6.2.4'))
|
44
|
+
assert_operator(oraver, :>, OCI8::OracleVersion.new('7.1.6.2.3'))
|
45
|
+
assert_operator(oraver, :>, OCI8::OracleVersion.new('8.0.6.2.3'))
|
46
|
+
assert_operator(oraver, :>, OCI8::OracleVersion.new('8.1.5.2.3'))
|
47
|
+
assert_operator(oraver, :>, OCI8::OracleVersion.new('8.1.6.1.3'))
|
48
|
+
assert_operator(oraver, :>, OCI8::OracleVersion.new('8.1.6.2.2'))
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_to_s
|
52
|
+
oraver = OCI8::OracleVersion.new('8.1.6.2.3')
|
53
|
+
assert_equal('8.1.6.2.3', oraver.to_s)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_to_i
|
57
|
+
oraver = OCI8::OracleVersion.new('8.1.6.2.3')
|
58
|
+
assert_equal(0x08106203, oraver.to_i)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_eql
|
62
|
+
oraver = OCI8::OracleVersion.new('8.1.6.2.3')
|
63
|
+
assert_equal(true, oraver.eql?(OCI8::OracleVersion.new('8.1.6.2.3')))
|
64
|
+
assert_equal(false, oraver.eql?(OCI8::OracleVersion.new('8.2.6.2.3')))
|
65
|
+
assert_equal(false, oraver.eql?('8.1.6.2.3'))
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|