ruby-oci8-master 2.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +2321 -0
- data/Makefile +88 -0
- data/NEWS +303 -0
- data/README +76 -0
- data/VERSION +1 -0
- data/dist-files +83 -0
- data/doc/api.en.html +527 -0
- data/doc/api.en.rd +554 -0
- data/doc/api.ja.html +525 -0
- data/doc/api.ja.rd +557 -0
- data/doc/manual.css +35 -0
- data/ext/oci8/.document +18 -0
- data/ext/oci8/MANIFEST +18 -0
- data/ext/oci8/apiwrap.c.tmpl +182 -0
- data/ext/oci8/apiwrap.h.tmpl +61 -0
- data/ext/oci8/apiwrap.rb +91 -0
- data/ext/oci8/apiwrap.yml +1455 -0
- data/ext/oci8/attr.c +105 -0
- data/ext/oci8/bind.c +366 -0
- data/ext/oci8/connection_pool.c +199 -0
- data/ext/oci8/encoding.c +289 -0
- data/ext/oci8/env.c +178 -0
- data/ext/oci8/error.c +378 -0
- data/ext/oci8/extconf.rb +179 -0
- data/ext/oci8/lob.c +805 -0
- data/ext/oci8/metadata.c +232 -0
- data/ext/oci8/object.c +727 -0
- data/ext/oci8/oci8.c +1156 -0
- data/ext/oci8/oci8.h +574 -0
- data/ext/oci8/oci8lib.c +527 -0
- data/ext/oci8/ocidatetime.c +484 -0
- data/ext/oci8/ocihandle.c +751 -0
- data/ext/oci8/ocinumber.c +1612 -0
- data/ext/oci8/oraconf.rb +1119 -0
- data/ext/oci8/oradate.c +611 -0
- data/ext/oci8/oranumber_util.c +352 -0
- data/ext/oci8/oranumber_util.h +24 -0
- data/ext/oci8/post-config.rb +5 -0
- data/ext/oci8/stmt.c +673 -0
- data/ext/oci8/thread_util.c +85 -0
- data/ext/oci8/thread_util.h +30 -0
- data/ext/oci8/win32.c +137 -0
- data/lib/.document +1 -0
- data/lib/dbd/OCI8.rb +591 -0
- data/lib/oci8.rb.in +94 -0
- data/lib/oci8/.document +8 -0
- data/lib/oci8/bindtype.rb +349 -0
- data/lib/oci8/compat.rb +113 -0
- data/lib/oci8/connection_pool.rb +99 -0
- data/lib/oci8/datetime.rb +611 -0
- data/lib/oci8/encoding-init.rb +74 -0
- data/lib/oci8/encoding.yml +537 -0
- data/lib/oci8/metadata.rb +2132 -0
- data/lib/oci8/object.rb +581 -0
- data/lib/oci8/oci8.rb +721 -0
- data/lib/oci8/ocihandle.rb +425 -0
- data/lib/oci8/oracle_version.rb +144 -0
- data/lib/oci8/properties.rb +73 -0
- data/metaconfig +142 -0
- data/pre-distclean.rb +7 -0
- data/ruby-oci8.gemspec +63 -0
- data/setup.rb +1331 -0
- data/test/README +4 -0
- data/test/config.rb +122 -0
- data/test/test_all.rb +51 -0
- data/test/test_appinfo.rb +63 -0
- data/test/test_array_dml.rb +333 -0
- data/test/test_bind_raw.rb +46 -0
- data/test/test_bind_time.rb +178 -0
- data/test/test_break.rb +96 -0
- data/test/test_clob.rb +82 -0
- data/test/test_connstr.rb +81 -0
- data/test/test_datetime.rb +582 -0
- data/test/test_dbi.rb +366 -0
- data/test/test_dbi_clob.rb +53 -0
- data/test/test_encoding.rb +100 -0
- data/test/test_error.rb +88 -0
- data/test/test_metadata.rb +1399 -0
- data/test/test_oci8.rb +434 -0
- data/test/test_oracle_version.rb +70 -0
- data/test/test_oradate.rb +256 -0
- data/test/test_oranumber.rb +746 -0
- data/test/test_rowid.rb +33 -0
- metadata +137 -0
data/test/test_oci8.rb
ADDED
@@ -0,0 +1,434 @@
|
|
1
|
+
require 'oci8'
|
2
|
+
require 'test/unit'
|
3
|
+
require File.dirname(__FILE__) + '/config'
|
4
|
+
require 'bigdecimal'
|
5
|
+
require 'rational'
|
6
|
+
|
7
|
+
class TestOCI8 < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@conn = get_oci8_connection
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
@conn.logoff
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_rename
|
18
|
+
drop_table('test_table')
|
19
|
+
drop_table('test_rename_table')
|
20
|
+
sql = <<-EOS
|
21
|
+
CREATE TABLE test_rename_table
|
22
|
+
(C CHAR(10) NOT NULL)
|
23
|
+
EOS
|
24
|
+
@conn.exec(sql)
|
25
|
+
@conn.exec("RENAME test_rename_table TO test_table")
|
26
|
+
drop_table('test_rename_table')
|
27
|
+
end
|
28
|
+
|
29
|
+
# USE_DYNAMIC_FETCH doesn't work well...
|
30
|
+
# This test is disabled.
|
31
|
+
def _test_long_type
|
32
|
+
drop_table('test_table')
|
33
|
+
@conn.exec('CREATE TABLE test_table (id number(38), lng long)')
|
34
|
+
test_data1 = 'a' * 70000
|
35
|
+
test_data2 = 'b' * 3000
|
36
|
+
test_data3 = nil
|
37
|
+
test_data4 = 'c' * 70000
|
38
|
+
@conn.exec('insert into test_table values (:1, :2)', 1, test_data1)
|
39
|
+
@conn.exec('insert into test_table values (:1, :2)', 2, [test_data2, :long])
|
40
|
+
@conn.exec('insert into test_table values (:1, :2)', 3, [nil, :long])
|
41
|
+
@conn.exec('insert into test_table values (:1, :2)', 4, [test_data4, :long])
|
42
|
+
|
43
|
+
[8000, 65535, 65536, 80000].each do |read_len|
|
44
|
+
@conn.long_read_len = read_len
|
45
|
+
cursor = @conn.parse('SELECT lng from test_table order by id')
|
46
|
+
cursor.exec
|
47
|
+
assert_equal(test_data1, cursor.fetch[0])
|
48
|
+
assert_equal(test_data2, cursor.fetch[0])
|
49
|
+
assert_equal(test_data3, cursor.fetch[0])
|
50
|
+
assert_equal(test_data4, cursor.fetch[0])
|
51
|
+
cursor.close
|
52
|
+
end
|
53
|
+
drop_table('test_table')
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_long_type
|
57
|
+
@conn.long_read_len = 80000
|
58
|
+
drop_table('test_table')
|
59
|
+
@conn.exec('CREATE TABLE test_table (id number(38), lng long)')
|
60
|
+
test_data1 = 'a' * 70000
|
61
|
+
test_data2 = 'b' * 3000
|
62
|
+
test_data3 = nil
|
63
|
+
test_data4 = 'c' * 70000
|
64
|
+
@conn.exec('insert into test_table values (:1, :2)', 1, test_data1)
|
65
|
+
@conn.exec('insert into test_table values (:1, :2)', 2, [test_data2, :long])
|
66
|
+
@conn.exec('insert into test_table values (:1, :2)', 3, [nil, :long])
|
67
|
+
@conn.exec('insert into test_table values (:1, :2)', 4, [test_data4, :long])
|
68
|
+
|
69
|
+
cursor = @conn.parse('SELECT lng from test_table order by id')
|
70
|
+
cursor.exec
|
71
|
+
assert_equal(test_data1, cursor.fetch[0])
|
72
|
+
assert_equal(test_data2, cursor.fetch[0])
|
73
|
+
assert_equal(test_data3, cursor.fetch[0])
|
74
|
+
assert_equal(test_data4, cursor.fetch[0])
|
75
|
+
cursor.close
|
76
|
+
drop_table('test_table')
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_select
|
80
|
+
drop_table('test_table')
|
81
|
+
sql = <<-EOS
|
82
|
+
CREATE TABLE test_table
|
83
|
+
(C CHAR(10) NOT NULL,
|
84
|
+
V VARCHAR2(20),
|
85
|
+
N NUMBER(10, 2),
|
86
|
+
D1 DATE, D2 DATE, D3 DATE, D4 DATE,
|
87
|
+
INT NUMBER(30), BIGNUM NUMBER(30))
|
88
|
+
STORAGE (
|
89
|
+
INITIAL 4k
|
90
|
+
NEXT 4k
|
91
|
+
MINEXTENTS 1
|
92
|
+
MAXEXTENTS UNLIMITED
|
93
|
+
PCTINCREASE 0)
|
94
|
+
EOS
|
95
|
+
@conn.exec(sql)
|
96
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:C, :V, :N, :D1, :D2, :D3, :D4, :INT, :BIGNUM)")
|
97
|
+
1.upto(10) do |i|
|
98
|
+
if i == 1
|
99
|
+
dt = [nil, OraDate]
|
100
|
+
else
|
101
|
+
dt = OraDate.new(2000 + i, 8, 3, 23, 59, 59)
|
102
|
+
end
|
103
|
+
cursor.exec(format("%10d", i * 10), i.to_s, i, dt, dt, dt, dt, i * 11111111111, i * 10000000000)
|
104
|
+
end
|
105
|
+
cursor.close
|
106
|
+
cursor = @conn.parse("SELECT * FROM test_table ORDER BY c")
|
107
|
+
cursor.define(5, Time) # define 5th column as Time
|
108
|
+
cursor.define(6, Date) # define 6th column as Date
|
109
|
+
cursor.define(7, DateTime) # define 7th column as DateTime
|
110
|
+
cursor.define(8, Integer) # define 8th column as Integer
|
111
|
+
cursor.define(9, Bignum) # define 9th column as Bignum
|
112
|
+
cursor.exec
|
113
|
+
assert_equal(["C", "V", "N", "D1", "D2", "D3", "D4", "INT", "BIGNUM"], cursor.get_col_names)
|
114
|
+
1.upto(10) do |i|
|
115
|
+
rv = cursor.fetch
|
116
|
+
assert_equal(format("%10d", i * 10), rv[0])
|
117
|
+
assert_equal(i.to_s, rv[1])
|
118
|
+
assert_equal(i, rv[2])
|
119
|
+
if i == 1
|
120
|
+
assert_nil(rv[3])
|
121
|
+
assert_nil(rv[4])
|
122
|
+
assert_nil(rv[5])
|
123
|
+
assert_nil(rv[6])
|
124
|
+
else
|
125
|
+
tm = Time.local(2000 + i, 8, 3, 23, 59, 59)
|
126
|
+
dt = Date.civil(2000 + i, 8, 3)
|
127
|
+
dttm = DateTime.civil(2000 + i, 8, 3, 23, 59, 59, Time.now.utc_offset.to_r/86400)
|
128
|
+
assert_equal(tm, rv[3])
|
129
|
+
assert_equal(tm, rv[4])
|
130
|
+
assert_equal(dt, rv[5])
|
131
|
+
assert_equal(dttm, rv[6])
|
132
|
+
end
|
133
|
+
assert_equal(i * 11111111111, rv[7])
|
134
|
+
assert_equal(i * 10000000000, rv[8])
|
135
|
+
end
|
136
|
+
assert_nil(cursor.fetch)
|
137
|
+
|
138
|
+
# fetch_hash with block
|
139
|
+
cursor.exec
|
140
|
+
i = 1
|
141
|
+
cursor.fetch_hash do |row|
|
142
|
+
assert_equal(format("%10d", i * 10), row['C'])
|
143
|
+
assert_equal(i.to_s, row['V'])
|
144
|
+
assert_equal(i, row['N'])
|
145
|
+
if i == 1
|
146
|
+
assert_nil(row['D1'])
|
147
|
+
assert_nil(row['D2'])
|
148
|
+
assert_nil(row['D3'])
|
149
|
+
assert_nil(row['D4'])
|
150
|
+
else
|
151
|
+
tm = Time.local(2000 + i, 8, 3, 23, 59, 59)
|
152
|
+
dt = Date.civil(2000 + i, 8, 3)
|
153
|
+
dttm = DateTime.civil(2000 + i, 8, 3, 23, 59, 59, Time.now.utc_offset.to_r/86400)
|
154
|
+
assert_equal(tm, row['D1'])
|
155
|
+
assert_equal(tm, row['D2'])
|
156
|
+
assert_equal(dt, row['D3'])
|
157
|
+
assert_equal(dttm, row['D4'])
|
158
|
+
end
|
159
|
+
assert_equal(i * 11111111111, row['INT'])
|
160
|
+
assert_equal(i * 10000000000, row['BIGNUM'])
|
161
|
+
i += 1
|
162
|
+
end
|
163
|
+
assert_equal(11, i)
|
164
|
+
|
165
|
+
cursor.close
|
166
|
+
drop_table('test_table')
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_bind_cursor
|
170
|
+
# FIXME: check again after upgrading Oracle 9.2 to 9.2.0.4.
|
171
|
+
return if $oracle_version < OCI8::ORAVER_10_1
|
172
|
+
|
173
|
+
drop_table('test_table')
|
174
|
+
sql = <<-EOS
|
175
|
+
CREATE TABLE test_table
|
176
|
+
(C CHAR(10) NOT NULL,
|
177
|
+
V VARCHAR2(20),
|
178
|
+
N NUMBER(10, 2),
|
179
|
+
D1 DATE, D2 DATE, D3 DATE,
|
180
|
+
INT NUMBER(30), BIGNUM NUMBER(30))
|
181
|
+
STORAGE (
|
182
|
+
INITIAL 4k
|
183
|
+
NEXT 4k
|
184
|
+
MINEXTENTS 1
|
185
|
+
MAXEXTENTS UNLIMITED
|
186
|
+
PCTINCREASE 0)
|
187
|
+
EOS
|
188
|
+
@conn.exec(sql)
|
189
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:C, :V, :N, :D1, :D2, :D3, :INT, :BIGNUM)")
|
190
|
+
1.upto(10) do |i|
|
191
|
+
if i == 1
|
192
|
+
dt = [nil, OraDate]
|
193
|
+
else
|
194
|
+
dt = OraDate.new(2000 + i, 8, 3, 23, 59, 59)
|
195
|
+
end
|
196
|
+
cursor.exec(format("%10d", i * 10), i.to_s, i, dt, dt, dt, i, i)
|
197
|
+
end
|
198
|
+
cursor.close
|
199
|
+
plsql = @conn.parse("BEGIN OPEN :cursor FOR SELECT * FROM test_table ORDER BY c; END;")
|
200
|
+
plsql.bind_param(':cursor', nil, OCI8::Cursor)
|
201
|
+
plsql.exec
|
202
|
+
cursor = plsql[':cursor']
|
203
|
+
cursor.define(5, Time) # define 5th column as Time
|
204
|
+
cursor.define(6, Date) # define 6th column as Date
|
205
|
+
cursor.define(7, Integer) # define 7th column as Integer
|
206
|
+
cursor.define(8, Bignum) # define 8th column as Integer
|
207
|
+
assert_equal(["C", "V", "N", "D1", "D2", "D3", "INT", "BIGNUM"], cursor.get_col_names)
|
208
|
+
1.upto(10) do |i|
|
209
|
+
rv = cursor.fetch
|
210
|
+
assert_equal(format("%10d", i * 10), rv[0])
|
211
|
+
assert_equal(i.to_s, rv[1])
|
212
|
+
assert_equal(i, rv[2])
|
213
|
+
if i == 1
|
214
|
+
assert_nil(rv[3])
|
215
|
+
assert_nil(rv[4])
|
216
|
+
assert_nil(rv[5])
|
217
|
+
else
|
218
|
+
dttm = DateTime.civil(2000 + i, 8, 3, 23, 59, 59, Time.now.utc_offset.to_r/86400)
|
219
|
+
tm = Time.local(2000 + i, 8, 3, 23, 59, 59)
|
220
|
+
dt = Date.civil(2000 + i, 8, 3)
|
221
|
+
assert_equal(tm, rv[3])
|
222
|
+
assert_equal(tm, rv[4])
|
223
|
+
assert_equal(dt, rv[5])
|
224
|
+
end
|
225
|
+
assert_equal(i, rv[6])
|
226
|
+
assert_equal(i, rv[7])
|
227
|
+
end
|
228
|
+
assert_nil(cursor.fetch)
|
229
|
+
cursor.close
|
230
|
+
drop_table('test_table')
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_cursor_in_result_set
|
234
|
+
drop_table('test_table')
|
235
|
+
sql = <<-EOS
|
236
|
+
CREATE TABLE test_table (N NUMBER(10, 2))
|
237
|
+
STORAGE (
|
238
|
+
INITIAL 4k
|
239
|
+
NEXT 4k
|
240
|
+
MINEXTENTS 1
|
241
|
+
MAXEXTENTS UNLIMITED
|
242
|
+
PCTINCREASE 0)
|
243
|
+
EOS
|
244
|
+
@conn.exec(sql)
|
245
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:1)")
|
246
|
+
1.upto(10) do |i|
|
247
|
+
cursor.exec(i)
|
248
|
+
end
|
249
|
+
cursor.close
|
250
|
+
cursor = @conn.exec(<<EOS)
|
251
|
+
select a.n, cursor (select a.n + b.n
|
252
|
+
from test_table b
|
253
|
+
order by n)
|
254
|
+
from test_table a
|
255
|
+
order by n
|
256
|
+
EOS
|
257
|
+
1.upto(10) do |i|
|
258
|
+
row = cursor.fetch
|
259
|
+
assert_equal(i, row[0])
|
260
|
+
cursor_in_result_set = row[1]
|
261
|
+
1.upto(10) do |j|
|
262
|
+
row2 = cursor_in_result_set.fetch
|
263
|
+
assert_equal(i + j, row2[0])
|
264
|
+
end
|
265
|
+
assert_nil(cursor_in_result_set.fetch) # check end of row data
|
266
|
+
cursor_in_result_set.close
|
267
|
+
end
|
268
|
+
assert_nil(cursor.fetch) # check end of row data
|
269
|
+
drop_table('test_table')
|
270
|
+
end
|
271
|
+
|
272
|
+
def test_binary_float
|
273
|
+
return if $oracle_version < OCI8::ORAVER_10_1
|
274
|
+
|
275
|
+
# Oracle 10g or upper
|
276
|
+
cursor = @conn.parse("select CAST(:1 AS BINARY_FLOAT), CAST(:2 AS BINARY_DOUBLE) from dual")
|
277
|
+
bind_val = -1.0
|
278
|
+
cursor.bind_param(1, 10.0, :binary_double)
|
279
|
+
cursor.bind_param(2, nil, :binary_double)
|
280
|
+
while bind_val < 10.0
|
281
|
+
cursor[2] = bind_val
|
282
|
+
cursor.exec
|
283
|
+
rv = cursor.fetch
|
284
|
+
assert_equal(10.0, rv[0])
|
285
|
+
assert_equal(bind_val, rv[1])
|
286
|
+
bind_val += 1.234
|
287
|
+
end
|
288
|
+
[-1.0/0.0, # -Infinite
|
289
|
+
+1.0/0.0, # +Infinite
|
290
|
+
0.0/0.0 # NaN
|
291
|
+
].each do |num|
|
292
|
+
cursor[1] = num
|
293
|
+
cursor[2] = num
|
294
|
+
cursor.exec
|
295
|
+
rv = cursor.fetch
|
296
|
+
if num.nan?
|
297
|
+
assert(rv[0].nan?)
|
298
|
+
assert(rv[1].nan?)
|
299
|
+
else
|
300
|
+
assert_equal(num, rv[0])
|
301
|
+
assert_equal(num, rv[1])
|
302
|
+
end
|
303
|
+
end
|
304
|
+
cursor.close
|
305
|
+
end
|
306
|
+
|
307
|
+
def test_clob_nclob_and_blob
|
308
|
+
return if OCI8::oracle_client_version < OCI8::ORAVER_8_1
|
309
|
+
|
310
|
+
drop_table('test_table')
|
311
|
+
sql = <<-EOS
|
312
|
+
CREATE TABLE test_table (id number(5), C CLOB, NC NCLOB, B BLOB)
|
313
|
+
STORAGE (
|
314
|
+
INITIAL 100k
|
315
|
+
NEXT 100k
|
316
|
+
MINEXTENTS 1
|
317
|
+
MAXEXTENTS UNLIMITED
|
318
|
+
PCTINCREASE 0)
|
319
|
+
EOS
|
320
|
+
@conn.exec(sql)
|
321
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:1, :2, :3, :4)")
|
322
|
+
0.upto(9) do |i|
|
323
|
+
val = format('%d', i) * 4096
|
324
|
+
cursor.exec(i, OCI8::CLOB.new(@conn, val), OCI8::NCLOB.new(@conn, val), OCI8::BLOB.new(@conn, val))
|
325
|
+
end
|
326
|
+
cursor.close
|
327
|
+
cursor = @conn.exec("select * from test_table order by id")
|
328
|
+
0.upto(9) do |i|
|
329
|
+
rv = cursor.fetch
|
330
|
+
val = format('%d', i) * 4096
|
331
|
+
assert_equal(i, rv[0])
|
332
|
+
assert_instance_of(OCI8::CLOB, rv[1])
|
333
|
+
assert_instance_of(OCI8::NCLOB, rv[2])
|
334
|
+
assert_instance_of(OCI8::BLOB, rv[3])
|
335
|
+
assert_equal(val, rv[1].read)
|
336
|
+
assert_equal(val.length, rv[2].size)
|
337
|
+
assert_equal(val, rv[2].read)
|
338
|
+
assert_equal(val, rv[3].read)
|
339
|
+
end
|
340
|
+
assert_nil(cursor.fetch)
|
341
|
+
cursor.close
|
342
|
+
drop_table('test_table')
|
343
|
+
end
|
344
|
+
|
345
|
+
def test_select_number
|
346
|
+
drop_table('test_table')
|
347
|
+
@conn.exec(<<EOS)
|
348
|
+
CREATE TABLE test_table (n NUMBER, n20 NUMBER(20), n14_2 NUMBER(14,2), n15_2 NUMBER(15,2), flt FLOAT)
|
349
|
+
STORAGE (
|
350
|
+
INITIAL 100k
|
351
|
+
NEXT 100k
|
352
|
+
MINEXTENTS 1
|
353
|
+
MAXEXTENTS UNLIMITED
|
354
|
+
PCTINCREASE 0)
|
355
|
+
EOS
|
356
|
+
@conn.exec(<<EOS)
|
357
|
+
INSERT INTO test_table values(12345678901234, 12345678901234567890, 123456789012.34, 1234567890123.45, 1234.5)
|
358
|
+
EOS
|
359
|
+
@conn.exec("select * from test_table") do |row|
|
360
|
+
assert_equal(row[0], 12345678901234)
|
361
|
+
assert_equal(row[1], 12345678901234567890)
|
362
|
+
assert_equal(row[2], 123456789012.34)
|
363
|
+
assert_equal(row[3], BigDecimal("1234567890123.45"))
|
364
|
+
assert_equal(row[4], 1234.5)
|
365
|
+
assert_instance_of(BigDecimal, row[0])
|
366
|
+
assert_instance_of(Bignum, row[1])
|
367
|
+
assert_instance_of(Float, row[2])
|
368
|
+
assert_instance_of(BigDecimal, row[3])
|
369
|
+
assert_instance_of(Float, row[4])
|
370
|
+
end
|
371
|
+
drop_table('test_table')
|
372
|
+
end
|
373
|
+
|
374
|
+
def test_bind_number_with_implicit_conversions
|
375
|
+
src = [1, 1.2, BigDecimal("1.2"), Rational(12, 10)]
|
376
|
+
int = [1, 1, 1, 1]
|
377
|
+
flt = [1, 1.2, 1.2, 1.2]
|
378
|
+
dec = [BigDecimal("1"), BigDecimal("1.2"), BigDecimal("1.2"), BigDecimal("1.2")]
|
379
|
+
rat = [Rational(1), Rational(12, 10), Rational(12, 10), Rational(12, 10)]
|
380
|
+
|
381
|
+
cursor = @conn.parse("begin :1 := :2; end;")
|
382
|
+
|
383
|
+
# Float
|
384
|
+
cursor.bind_param(1, nil, Float)
|
385
|
+
cursor.bind_param(2, nil, Float)
|
386
|
+
src.each_with_index do |s, idx|
|
387
|
+
cursor[2] = s
|
388
|
+
cursor.exec
|
389
|
+
assert_equal(cursor[1], flt[idx])
|
390
|
+
assert_kind_of(Float, cursor[1])
|
391
|
+
end
|
392
|
+
|
393
|
+
# Fixnum
|
394
|
+
cursor.bind_param(1, nil, Fixnum)
|
395
|
+
cursor.bind_param(2, nil, Fixnum)
|
396
|
+
src.each_with_index do |s, idx|
|
397
|
+
cursor[2] = s
|
398
|
+
cursor.exec
|
399
|
+
assert_equal(cursor[1], int[idx])
|
400
|
+
assert_kind_of(Fixnum, cursor[1])
|
401
|
+
end
|
402
|
+
|
403
|
+
# Integer
|
404
|
+
cursor.bind_param(1, nil, Integer)
|
405
|
+
cursor.bind_param(2, nil, Integer)
|
406
|
+
src.each_with_index do |s, idx|
|
407
|
+
cursor[2] = s
|
408
|
+
cursor.exec
|
409
|
+
assert_equal(cursor[1], int[idx])
|
410
|
+
assert_kind_of(Integer, cursor[1])
|
411
|
+
end
|
412
|
+
|
413
|
+
# BigDecimal
|
414
|
+
cursor.bind_param(1, nil, BigDecimal)
|
415
|
+
cursor.bind_param(2, nil, BigDecimal)
|
416
|
+
src.each_with_index do |s, idx|
|
417
|
+
cursor[2] = s
|
418
|
+
cursor.exec
|
419
|
+
assert_equal(cursor[1], dec[idx])
|
420
|
+
assert_kind_of(BigDecimal, cursor[1])
|
421
|
+
end
|
422
|
+
|
423
|
+
# Rational
|
424
|
+
cursor.bind_param(1, nil, Rational)
|
425
|
+
cursor.bind_param(2, nil, Rational)
|
426
|
+
src.each_with_index do |s, idx|
|
427
|
+
cursor[2] = s
|
428
|
+
cursor.exec
|
429
|
+
assert_equal(cursor[1], rat[idx])
|
430
|
+
assert_kind_of(Rational, cursor[1])
|
431
|
+
end
|
432
|
+
end
|
433
|
+
|
434
|
+
end # TestOCI8
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'oci8'
|
2
|
+
require 'test/unit'
|
3
|
+
require File.dirname(__FILE__) + '/config'
|
4
|
+
|
5
|
+
class TestOracleVersion < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_init
|
8
|
+
oraver = OCI8::OracleVersion.new('8.1.6.2.3')
|
9
|
+
assert_equal(8, oraver.major)
|
10
|
+
assert_equal(1, oraver.minor)
|
11
|
+
assert_equal(6, oraver.update)
|
12
|
+
assert_equal(2, oraver.patch)
|
13
|
+
assert_equal(3, oraver.port_update)
|
14
|
+
|
15
|
+
oraver = OCI8::OracleVersion.new('8.1.6')
|
16
|
+
assert_equal(8, oraver.major)
|
17
|
+
assert_equal(1, oraver.minor)
|
18
|
+
assert_equal(6, oraver.update)
|
19
|
+
assert_equal(0, oraver.patch)
|
20
|
+
assert_equal(0, oraver.port_update)
|
21
|
+
|
22
|
+
oraver = OCI8::OracleVersion.new('10')
|
23
|
+
assert_equal(10, oraver.major)
|
24
|
+
assert_equal(0, oraver.minor)
|
25
|
+
assert_equal(0, oraver.update)
|
26
|
+
assert_equal(0, oraver.patch)
|
27
|
+
assert_equal(0, oraver.port_update)
|
28
|
+
|
29
|
+
oraver = OCI8::OracleVersion.new(0x08106203)
|
30
|
+
assert_equal(8, oraver.major)
|
31
|
+
assert_equal(1, oraver.minor)
|
32
|
+
assert_equal(6, oraver.update)
|
33
|
+
assert_equal(2, oraver.patch)
|
34
|
+
assert_equal(3, oraver.port_update)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_compare
|
38
|
+
oraver = OCI8::OracleVersion.new('8.1.6.2.3')
|
39
|
+
assert_operator(oraver, :==, OCI8::OracleVersion.new('8.1.6.2.3'))
|
40
|
+
assert_operator(oraver, :<, OCI8::OracleVersion.new('9.1.6.2.3'))
|
41
|
+
assert_operator(oraver, :<, OCI8::OracleVersion.new('8.2.6.2.3'))
|
42
|
+
assert_operator(oraver, :<, OCI8::OracleVersion.new('8.1.7.2.3'))
|
43
|
+
assert_operator(oraver, :<, OCI8::OracleVersion.new('8.1.6.3.3'))
|
44
|
+
assert_operator(oraver, :<, OCI8::OracleVersion.new('8.1.6.2.4'))
|
45
|
+
assert_operator(oraver, :>, OCI8::OracleVersion.new('7.1.6.2.3'))
|
46
|
+
assert_operator(oraver, :>, OCI8::OracleVersion.new('8.0.6.2.3'))
|
47
|
+
assert_operator(oraver, :>, OCI8::OracleVersion.new('8.1.5.2.3'))
|
48
|
+
assert_operator(oraver, :>, OCI8::OracleVersion.new('8.1.6.1.3'))
|
49
|
+
assert_operator(oraver, :>, OCI8::OracleVersion.new('8.1.6.2.2'))
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_to_s
|
53
|
+
oraver = OCI8::OracleVersion.new('8.1.6.2.3')
|
54
|
+
assert_equal('8.1.6.2.3', oraver.to_s)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_to_i
|
58
|
+
oraver = OCI8::OracleVersion.new('8.1.6.2.3')
|
59
|
+
assert_equal(0x08106203, oraver.to_i)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_eql
|
63
|
+
oraver = OCI8::OracleVersion.new('8.1.6.2.3')
|
64
|
+
assert_equal(true, oraver.eql?(OCI8::OracleVersion.new('8.1.6.2.3')))
|
65
|
+
assert_equal(false, oraver.eql?(OCI8::OracleVersion.new('8.2.6.2.3')))
|
66
|
+
assert_equal(false, oraver.eql?('8.1.6.2.3'))
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
Test::Unit::AutoRunner.run() if $0 == __FILE__
|