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
@@ -0,0 +1,332 @@
|
|
1
|
+
require 'oci8'
|
2
|
+
require File.dirname(__FILE__) + '/config'
|
3
|
+
|
4
|
+
class TestArrayDML < Minitest::Test
|
5
|
+
def setup
|
6
|
+
@conn = get_oci8_connection
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
@conn.logoff
|
11
|
+
end
|
12
|
+
|
13
|
+
# test inserting arrays with different data types
|
14
|
+
# including char, varchar2, number, date and so on
|
15
|
+
def test_array_insert1
|
16
|
+
drop_table('test_table')
|
17
|
+
sql = <<-EOS
|
18
|
+
CREATE TABLE test_table
|
19
|
+
(C CHAR(10) NOT NULL,
|
20
|
+
V VARCHAR2(20),
|
21
|
+
N NUMBER(10, 2),
|
22
|
+
D DATE,
|
23
|
+
INT NUMBER(30),
|
24
|
+
BIGNUM NUMBER(30),
|
25
|
+
T TIMESTAMP)
|
26
|
+
STORAGE (
|
27
|
+
INITIAL 4k
|
28
|
+
NEXT 4k
|
29
|
+
MINEXTENTS 1
|
30
|
+
MAXEXTENTS UNLIMITED
|
31
|
+
PCTINCREASE 0)
|
32
|
+
EOS
|
33
|
+
@conn.exec(sql)
|
34
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:C, :V, :N, :D, :INT, :BIGNUM, :T)")
|
35
|
+
max_array_size = 3
|
36
|
+
cursor.max_array_size= max_array_size
|
37
|
+
|
38
|
+
cursor.bind_param_array(1, nil, String)
|
39
|
+
cursor.bind_param_array(2, nil ,String)
|
40
|
+
cursor.bind_param_array(3, nil, Fixnum)
|
41
|
+
cursor.bind_param_array(4, nil, OraDate)
|
42
|
+
cursor.bind_param_array(5, nil, Integer)
|
43
|
+
cursor.bind_param_array(6, nil, Bignum)
|
44
|
+
cursor.bind_param_array(7, nil, DateTime)
|
45
|
+
|
46
|
+
c_arr = Array.new
|
47
|
+
v_arr = Array.new
|
48
|
+
n_arr = Array.new
|
49
|
+
d_arr = Array.new
|
50
|
+
int_arr = Array.new
|
51
|
+
bignum_arr = Array.new
|
52
|
+
t_arr = Array.new
|
53
|
+
|
54
|
+
1.upto(30) do |i|
|
55
|
+
c_arr << format("%10d", i * 10)
|
56
|
+
v_arr << i.to_s
|
57
|
+
n_arr << i
|
58
|
+
d_arr << OraDate.new(2000 + i, 12, 24, 23, 59, 59)
|
59
|
+
int_arr << i * 11111111111
|
60
|
+
bignum_arr << i * 10000000000
|
61
|
+
t_arr << DateTime.new(2000 + i, 12, 24, 23, 59, 59)
|
62
|
+
|
63
|
+
if i%max_array_size == 0
|
64
|
+
cursor[1] = c_arr
|
65
|
+
cursor[2] = v_arr
|
66
|
+
cursor[3] = n_arr
|
67
|
+
cursor[4] = d_arr
|
68
|
+
cursor[5] = int_arr
|
69
|
+
cursor[6] = bignum_arr
|
70
|
+
cursor[7] = t_arr
|
71
|
+
|
72
|
+
r = cursor.exec_array
|
73
|
+
assert_equal(max_array_size, r)
|
74
|
+
assert_equal(c_arr, cursor[1])
|
75
|
+
assert_equal(v_arr, cursor[2])
|
76
|
+
assert_equal(n_arr, cursor[3])
|
77
|
+
assert_equal(d_arr, cursor[4])
|
78
|
+
assert_equal(int_arr, cursor[5])
|
79
|
+
assert_equal(bignum_arr, cursor[6])
|
80
|
+
assert_equal(t_arr, cursor[7])
|
81
|
+
c_arr.clear
|
82
|
+
v_arr.clear
|
83
|
+
n_arr.clear
|
84
|
+
d_arr.clear
|
85
|
+
int_arr.clear
|
86
|
+
bignum_arr.clear
|
87
|
+
t_arr.clear
|
88
|
+
end
|
89
|
+
end
|
90
|
+
cursor.close
|
91
|
+
|
92
|
+
cursor = @conn.parse("SELECT * FROM test_table ORDER BY c")
|
93
|
+
cursor.define(5, Integer)
|
94
|
+
cursor.define(6, Bignum)
|
95
|
+
cursor.exec
|
96
|
+
assert_equal(["C","V","N","D","INT","BIGNUM","T"], cursor.get_col_names)
|
97
|
+
1.upto(30) do |i|
|
98
|
+
rv = cursor.fetch
|
99
|
+
assert_equal(format("%10d", i * 10), rv[0])
|
100
|
+
assert_equal(i.to_s, rv[1])
|
101
|
+
assert_equal(i, rv[2])
|
102
|
+
tm = Time.local(2000 + i, 12, 24, 23, 59, 59)
|
103
|
+
assert_equal(tm, rv[3])
|
104
|
+
assert_equal(i * 11111111111, rv[4])
|
105
|
+
assert_equal(i * 10000000000, rv[5])
|
106
|
+
assert_equal(tm, rv[6])
|
107
|
+
end
|
108
|
+
assert_nil(cursor.fetch)
|
109
|
+
drop_table('test_table')
|
110
|
+
end
|
111
|
+
|
112
|
+
# Raise error when binding arrays are not the same size
|
113
|
+
def test_array_insert2
|
114
|
+
drop_table('test_table')
|
115
|
+
sql = <<-EOS
|
116
|
+
CREATE TABLE test_table
|
117
|
+
(N NUMBER(10, 2) NOT NULL,
|
118
|
+
V VARCHAR(20))
|
119
|
+
EOS
|
120
|
+
@conn.exec(sql)
|
121
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:N, :V)")
|
122
|
+
max_array_size = 10
|
123
|
+
cursor.max_array_size = max_array_size
|
124
|
+
cursor.bind_param_array(1, nil, Fixnum)
|
125
|
+
cursor.bind_param_array(2, nil, String)
|
126
|
+
n_arr = Array.new
|
127
|
+
v_arr = Array.new
|
128
|
+
1.upto(max_array_size) do |i|
|
129
|
+
n_arr << i
|
130
|
+
v_arr << i.to_s if i != max_array_size
|
131
|
+
end
|
132
|
+
cursor[1] = n_arr
|
133
|
+
assert_raises(RuntimeError) { cursor[2] = v_arr }
|
134
|
+
cursor.close
|
135
|
+
|
136
|
+
drop_table('test_table')
|
137
|
+
end
|
138
|
+
|
139
|
+
# All binds are clear from cursor after calling "max_array_size=",
|
140
|
+
# in that case, you have to re-bind the array parameters
|
141
|
+
# otherwise, an error will be raised.
|
142
|
+
def test_array_insert3
|
143
|
+
drop_table('test_table')
|
144
|
+
sql = <<-EOS
|
145
|
+
CREATE TABLE test_table
|
146
|
+
(N NUMBER(10, 2) NOT NULL,
|
147
|
+
V VARCHAR(20),
|
148
|
+
T TIMESTAMP)
|
149
|
+
EOS
|
150
|
+
@conn.exec(sql)
|
151
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:N, :V, :T)")
|
152
|
+
cursor.max_array_size = 3
|
153
|
+
cursor.bind_param_array(1, [1, 2, 3])
|
154
|
+
cursor.bind_param_array(2, ['happy', 'new', 'year'])
|
155
|
+
cursor.bind_param_array(3, [Time.gm(1990,1,1), Time.gm(2000,1,1), Time.gm(2010,1,1)])
|
156
|
+
cursor.exec_array
|
157
|
+
cursor.max_array_size = 2
|
158
|
+
assert_raises(RuntimeError) { cursor.exec_array }
|
159
|
+
drop_table('test_table')
|
160
|
+
end
|
161
|
+
|
162
|
+
# The size of binding arrays are not required to be same as max_array_size. The
|
163
|
+
# only requirement is that they should be the same size, and the size will be
|
164
|
+
# used as execution count for OCIStmtExecute.
|
165
|
+
def test_array_insert4
|
166
|
+
drop_table('test_table')
|
167
|
+
sql = <<-EOS
|
168
|
+
CREATE TABLE test_table
|
169
|
+
(N NUMBER(10, 2) NOT NULL,
|
170
|
+
V VARCHAR(20))
|
171
|
+
EOS
|
172
|
+
@conn.exec(sql)
|
173
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:N, :V)")
|
174
|
+
max_array_size = 4
|
175
|
+
cursor.max_array_size = max_array_size
|
176
|
+
cursor.bind_param_array(1, nil, Fixnum)
|
177
|
+
cursor.bind_param_array(2, nil, String)
|
178
|
+
n_arr = Array.new
|
179
|
+
v_arr = Array.new
|
180
|
+
1.upto( max_array_size - 1 ) do |i|
|
181
|
+
n_arr << i
|
182
|
+
v_arr << i.to_s
|
183
|
+
end
|
184
|
+
cursor[1] = n_arr
|
185
|
+
cursor[2] = v_arr
|
186
|
+
cursor.exec_array
|
187
|
+
cursor.close
|
188
|
+
|
189
|
+
cursor = @conn.parse("SELECT * FROM test_table ORDER BY N")
|
190
|
+
cursor.exec
|
191
|
+
1.upto( max_array_size - 1 ) do |i|
|
192
|
+
rv = cursor.fetch
|
193
|
+
assert_equal(i, rv[0])
|
194
|
+
assert_equal(i.to_s, rv[1])
|
195
|
+
end
|
196
|
+
assert_nil(cursor.fetch)
|
197
|
+
cursor.close
|
198
|
+
drop_table('test_table')
|
199
|
+
end
|
200
|
+
|
201
|
+
# Inserting "nil" elements with array dml raises an error
|
202
|
+
def test_array_insert5
|
203
|
+
drop_table('test_table')
|
204
|
+
sql = <<-EOS
|
205
|
+
CREATE TABLE test_table
|
206
|
+
(N NUMBER(10, 2),
|
207
|
+
V VARCHAR(20))
|
208
|
+
EOS
|
209
|
+
@conn.exec(sql)
|
210
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:N, :V)")
|
211
|
+
max_array_size = 3
|
212
|
+
cursor.max_array_size = max_array_size
|
213
|
+
cursor.bind_param_array(1, nil, Fixnum)
|
214
|
+
cursor.bind_param_array(2, nil, String)
|
215
|
+
assert_raises(RuntimeError) { cursor.exec_array }
|
216
|
+
cursor.close
|
217
|
+
drop_table('test_table')
|
218
|
+
end
|
219
|
+
|
220
|
+
# delete with array bindings
|
221
|
+
def test_array_delete
|
222
|
+
drop_table('test_table')
|
223
|
+
sql = <<-EOS
|
224
|
+
CREATE TABLE test_table
|
225
|
+
(N NUMBER(10, 2),
|
226
|
+
V VARCHAR(20))
|
227
|
+
EOS
|
228
|
+
@conn.exec(sql)
|
229
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:N, :V)")
|
230
|
+
max_array_size = 10
|
231
|
+
cursor.max_array_size = max_array_size
|
232
|
+
n_arr = Array.new
|
233
|
+
v_arr = Array.new
|
234
|
+
1.upto( max_array_size) do |i|
|
235
|
+
n_arr << i
|
236
|
+
v_arr << i.to_s
|
237
|
+
end
|
238
|
+
cursor.bind_param_array(1, nil, Fixnum)
|
239
|
+
cursor.bind_param_array(2, nil, String)
|
240
|
+
cursor[1] = n_arr
|
241
|
+
cursor[2] = v_arr
|
242
|
+
cursor.exec_array
|
243
|
+
cursor.close
|
244
|
+
|
245
|
+
cursor = @conn.parse("DELETE FROM test_table WHERE N=:1")
|
246
|
+
cursor.max_array_size = max_array_size
|
247
|
+
delete_arr = Array.new
|
248
|
+
1.upto(max_array_size) do |i|
|
249
|
+
if i%2 == 0
|
250
|
+
delete_arr << i
|
251
|
+
end
|
252
|
+
end
|
253
|
+
cursor.bind_param_array(1, nil, Fixnum)
|
254
|
+
cursor[1] = delete_arr
|
255
|
+
cursor.exec_array
|
256
|
+
cursor.close
|
257
|
+
|
258
|
+
cursor = @conn.parse("SELECT * FROM test_table ORDER BY N")
|
259
|
+
cursor.exec
|
260
|
+
1.upto( max_array_size ) do |i|
|
261
|
+
if i%2 != 0
|
262
|
+
rv = cursor.fetch
|
263
|
+
assert_equal(rv[0], i)
|
264
|
+
assert_equal(rv[1], i.to_s)
|
265
|
+
end
|
266
|
+
end
|
267
|
+
assert_nil(cursor.fetch)
|
268
|
+
cursor.close
|
269
|
+
|
270
|
+
drop_table('test_table')
|
271
|
+
end
|
272
|
+
|
273
|
+
# update with array bindings
|
274
|
+
def test_array_update
|
275
|
+
drop_table('test_table')
|
276
|
+
sql = <<-EOS
|
277
|
+
CREATE TABLE test_table
|
278
|
+
(N NUMBER(10, 2),
|
279
|
+
V VARCHAR(20))
|
280
|
+
EOS
|
281
|
+
@conn.exec(sql)
|
282
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:N, :V)")
|
283
|
+
max_array_size = 10
|
284
|
+
cursor.max_array_size = max_array_size
|
285
|
+
n_arr = Array.new
|
286
|
+
v_arr = Array.new
|
287
|
+
1.upto( max_array_size) do |i|
|
288
|
+
n_arr << i
|
289
|
+
v_arr << i.to_s
|
290
|
+
end
|
291
|
+
cursor.bind_param_array(1, nil, Fixnum)
|
292
|
+
cursor.bind_param_array(2, nil, String)
|
293
|
+
cursor[1] = n_arr
|
294
|
+
cursor[2] = v_arr
|
295
|
+
cursor.exec_array
|
296
|
+
cursor.close
|
297
|
+
|
298
|
+
cursor = @conn.parse("UPDATE test_table SET V=:1 WHERE N=:2")
|
299
|
+
cursor.max_array_size = max_array_size
|
300
|
+
update_arr = Array.new
|
301
|
+
update_v_arr = Array.new
|
302
|
+
1.upto(max_array_size) do |i|
|
303
|
+
if i%2 == 0
|
304
|
+
update_arr << i
|
305
|
+
update_v_arr << (i * 10).to_s
|
306
|
+
end
|
307
|
+
end
|
308
|
+
cursor.bind_param_array(1, nil, String)
|
309
|
+
cursor.bind_param_array(2, nil, Fixnum)
|
310
|
+
cursor[1] = update_v_arr
|
311
|
+
cursor[2] = update_arr
|
312
|
+
cursor.exec_array
|
313
|
+
cursor.close
|
314
|
+
|
315
|
+
cursor = @conn.parse("SELECT * FROM test_table ORDER BY N")
|
316
|
+
cursor.exec
|
317
|
+
1.upto( max_array_size ) do |i|
|
318
|
+
rv = cursor.fetch
|
319
|
+
if i%2 != 0
|
320
|
+
assert_equal(rv[0], i)
|
321
|
+
assert_equal(rv[1], i.to_s)
|
322
|
+
else
|
323
|
+
assert_equal(rv[0], i)
|
324
|
+
assert_equal(rv[1], (i * 10).to_s)
|
325
|
+
end
|
326
|
+
end
|
327
|
+
assert_nil(cursor.fetch)
|
328
|
+
|
329
|
+
cursor.close
|
330
|
+
drop_table('test_table')
|
331
|
+
end
|
332
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'oci8'
|
2
|
+
require File.dirname(__FILE__) + '/config'
|
3
|
+
|
4
|
+
class TestBindArray < Minitest::Test
|
5
|
+
|
6
|
+
def test_bind_array_names
|
7
|
+
assert_equal(":id_0", OCI8::in_cond(:id, []).names)
|
8
|
+
assert_equal(":id_0", OCI8::in_cond(:id, [1]).names)
|
9
|
+
assert_equal(":id_0, :id_1", OCI8::in_cond(:id, [1, 2]).names)
|
10
|
+
assert_equal(":id_0, :id_1, :id_2", OCI8::in_cond(:id, [1, 2, 3]).names)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_bind_array_values
|
14
|
+
assert_equal([[nil, String, nil]], OCI8::in_cond(:id, []).values)
|
15
|
+
assert_equal([[1, nil, nil]], OCI8::in_cond(:id, [1]).values)
|
16
|
+
assert_equal([[1, nil, nil], [2, nil, nil]], OCI8::in_cond(:id, [1, 2]).values)
|
17
|
+
assert_equal([[1, nil, nil], [2, nil, nil], [3, nil, nil]], OCI8::in_cond(:id, [1, 2, 3]).values)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_bind_array_values_containg_nil
|
21
|
+
assert_equal([[nil, String]], OCI8::in_cond(:id, [nil]).values)
|
22
|
+
assert_equal([[nil, Fixnum], [2, nil, nil], [3, nil, nil]], OCI8::in_cond(:id, [nil, 2, 3]).values)
|
23
|
+
assert_equal([[1, nil, nil], [nil, Fixnum], [3, nil, nil]], OCI8::in_cond(:id, [1, nil, 3]).values)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_bind_array_values_with_type
|
27
|
+
assert_equal([[nil, Integer, nil]], OCI8::in_cond(:id, [], Integer).values)
|
28
|
+
assert_equal([[1, Integer, nil]], OCI8::in_cond(:id, [1], Integer).values)
|
29
|
+
assert_equal([[1, Integer, nil], [2, Integer, nil]], OCI8::in_cond(:id, [1, 2], Integer).values)
|
30
|
+
assert_equal([[1, Integer, nil], [2, Integer, nil], [3, Integer, nil]], OCI8::in_cond(:id, [1, 2, 3], Integer).values)
|
31
|
+
assert_equal([[nil, Integer, nil], [2, Integer, nil], [3, Integer, nil]], OCI8::in_cond(:id, [nil, 2, 3], Integer).values)
|
32
|
+
assert_equal([[1, Integer, nil], [nil, Integer, nil], [3, Integer, nil]], OCI8::in_cond(:id, [1, nil, 3], Integer).values)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_select
|
36
|
+
@conn = get_oci8_connection
|
37
|
+
begin
|
38
|
+
drop_table('test_table')
|
39
|
+
@conn.exec(<<EOS)
|
40
|
+
CREATE TABLE test_table (ID NUMBER(38))
|
41
|
+
EOS
|
42
|
+
cursor = @conn.parse('insert into test_table values(:1)')
|
43
|
+
cursor.bind_param(1, nil, Integer)
|
44
|
+
[1, 3, 5].each do |id|
|
45
|
+
cursor.exec(id)
|
46
|
+
end
|
47
|
+
cursor.close
|
48
|
+
|
49
|
+
[
|
50
|
+
[],
|
51
|
+
[1],
|
52
|
+
[1, 2],
|
53
|
+
[1, 2, 3],
|
54
|
+
[nil],
|
55
|
+
[nil, 2, 3],
|
56
|
+
[1, nil, 3],
|
57
|
+
].each do |ids|
|
58
|
+
in_cond = OCI8::in_cond(:id, ids)
|
59
|
+
cursor = @conn.exec("select * from test_table where id in (#{in_cond.names}) order by id", *in_cond.values)
|
60
|
+
([1, 3, 5] & ids).each do |id|
|
61
|
+
assert_equal(id, cursor.fetch[0])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
drop_table('test_table')
|
66
|
+
ensure
|
67
|
+
@conn.logoff
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# Low-level API
|
2
|
+
require 'oci8'
|
3
|
+
require File.dirname(__FILE__) + '/config'
|
4
|
+
|
5
|
+
class TestBindBoolean < Minitest::Test
|
6
|
+
def setup
|
7
|
+
@conn = get_oci8_connection()
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_set_raw
|
11
|
+
stmt = <<EOS
|
12
|
+
DECLARE
|
13
|
+
bool_val boolean;
|
14
|
+
int_val pls_integer;
|
15
|
+
BEGIN
|
16
|
+
bool_val := :in;
|
17
|
+
IF bool_val THEN
|
18
|
+
int_val := 1;
|
19
|
+
ELSE
|
20
|
+
int_val := 0;
|
21
|
+
END IF;
|
22
|
+
:out := int_val;
|
23
|
+
END;
|
24
|
+
EOS
|
25
|
+
# explicit bind
|
26
|
+
cursor = @conn.parse(stmt)
|
27
|
+
cursor.bind_param(:in, nil, TrueClass)
|
28
|
+
cursor.bind_param(:out, nil, Integer)
|
29
|
+
|
30
|
+
cursor[:in] = true
|
31
|
+
cursor.exec
|
32
|
+
assert_equal(1, cursor[:out])
|
33
|
+
|
34
|
+
cursor[:in] = false
|
35
|
+
cursor.exec
|
36
|
+
assert_equal(0, cursor[:out])
|
37
|
+
|
38
|
+
# implicit bind
|
39
|
+
do_block_cnt = 0
|
40
|
+
@conn.exec(stmt, true, 0) do |in_val, out_val|
|
41
|
+
assert_equal(true, in_val)
|
42
|
+
assert_equal(1, out_val)
|
43
|
+
do_block_cnt += 1
|
44
|
+
end
|
45
|
+
|
46
|
+
@conn.exec(stmt, false, 0) do |in_val, out_val|
|
47
|
+
assert_equal(false, in_val)
|
48
|
+
assert_equal(0, out_val)
|
49
|
+
do_block_cnt += 1
|
50
|
+
end
|
51
|
+
assert_equal(2, do_block_cnt)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_get_raw
|
55
|
+
stmt = <<EOS
|
56
|
+
DECLARE
|
57
|
+
int_val pls_integer;
|
58
|
+
bool_val boolean;
|
59
|
+
BEGIN
|
60
|
+
int_val := :in;
|
61
|
+
IF int_val <> 0 THEN
|
62
|
+
bool_val := TRUE;
|
63
|
+
ELSE
|
64
|
+
bool_val := FALSE;
|
65
|
+
END IF;
|
66
|
+
:out := bool_val;
|
67
|
+
END;
|
68
|
+
EOS
|
69
|
+
cursor = @conn.parse(stmt)
|
70
|
+
cursor.bind_param(:in, nil, Integer)
|
71
|
+
cursor.bind_param(:out, nil, TrueClass)
|
72
|
+
|
73
|
+
cursor[:in] = 1
|
74
|
+
cursor.exec
|
75
|
+
assert_equal(true, cursor[:out])
|
76
|
+
|
77
|
+
cursor[:in] = 0
|
78
|
+
cursor.exec
|
79
|
+
assert_equal(false, cursor[:out])
|
80
|
+
|
81
|
+
do_block_cnt = 0
|
82
|
+
@conn.exec(stmt, 1, true) do |in_val, out_val|
|
83
|
+
assert_equal(1, in_val)
|
84
|
+
assert_equal(true, out_val)
|
85
|
+
do_block_cnt += 1
|
86
|
+
end
|
87
|
+
|
88
|
+
@conn.exec(stmt, 0, true) do |in_val, out_val|
|
89
|
+
assert_equal(0, in_val)
|
90
|
+
assert_equal(false, out_val)
|
91
|
+
do_block_cnt += 1
|
92
|
+
end
|
93
|
+
assert_equal(2, do_block_cnt)
|
94
|
+
end
|
95
|
+
|
96
|
+
def teardown
|
97
|
+
@conn.logoff
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'oci8'
|
2
|
+
require File.dirname(__FILE__) + '/config'
|
3
|
+
|
4
|
+
class TestBindInteger < Minitest::Test
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@conn = get_oci8_connection
|
8
|
+
end
|
9
|
+
|
10
|
+
POSITIVE_INTS = [
|
11
|
+
100,
|
12
|
+
2**30,
|
13
|
+
2**31,
|
14
|
+
2**32,
|
15
|
+
2**33,
|
16
|
+
2**62,
|
17
|
+
2**63,
|
18
|
+
2**64,
|
19
|
+
('9' * 38).to_i
|
20
|
+
]
|
21
|
+
|
22
|
+
def bind_and_get(input_value, output_type)
|
23
|
+
cursor = @conn.parse("BEGIN :out := :in; END;")
|
24
|
+
cursor.bind_param(:out, output_type)
|
25
|
+
cursor.bind_param(:in, input_value)
|
26
|
+
cursor.exec
|
27
|
+
result = cursor[:out]
|
28
|
+
cursor.close
|
29
|
+
result
|
30
|
+
end
|
31
|
+
|
32
|
+
(POSITIVE_INTS + [0] + POSITIVE_INTS.map(&:-@)).each do |num|
|
33
|
+
define_method("test_bind_param_with_input_of '#{num}'") do
|
34
|
+
assert_equal(OraNumber.new(num.to_s), bind_and_get(num, OraNumber))
|
35
|
+
end
|
36
|
+
|
37
|
+
define_method("test_bind_param_with_output_of '#{num}'") do
|
38
|
+
result = bind_and_get(OraNumber.new(num.to_s), Integer)
|
39
|
+
assert_equal(num, result)
|
40
|
+
assert_kind_of(Integer, result)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def teardown
|
45
|
+
@conn.logoff
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# Low-level API
|
2
|
+
require 'oci8'
|
3
|
+
require File.dirname(__FILE__) + '/config'
|
4
|
+
|
5
|
+
class TestBindRaw < Minitest::Test
|
6
|
+
CHECK_TARGET = [
|
7
|
+
["0123456789:;<=>?", "303132333435363738393A3B3C3D3E3F"],
|
8
|
+
["@ABCDEFGHIJKLMNO", "404142434445464748494A4B4C4D4E4F"],
|
9
|
+
["PQRSTUVWXYZ[\\]^_", "505152535455565758595A5B5C5D5E5F"],
|
10
|
+
["`abcdefghijklmno", "606162636465666768696A6B6C6D6E6F"],
|
11
|
+
["pqrstuvwxyz{|}~", "707172737475767778797A7B7C7D7E"],
|
12
|
+
]
|
13
|
+
|
14
|
+
def setup
|
15
|
+
@conn = get_oci8_connection()
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_set_raw
|
19
|
+
cursor = @conn.parse("BEGIN :hex := RAWTOHEX(:raw); END;")
|
20
|
+
cursor.bind_param(:raw, nil, OCI8::RAW, 16)
|
21
|
+
cursor.bind_param(:hex, nil, String, 32)
|
22
|
+
|
23
|
+
CHECK_TARGET.each do |raw, hex|
|
24
|
+
cursor[:raw] = raw
|
25
|
+
cursor.exec
|
26
|
+
assert_equal(hex, cursor[:hex])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_get_raw
|
31
|
+
cursor = @conn.parse("BEGIN :raw := HEXTORAW(:hex); END;")
|
32
|
+
cursor.bind_param(:hex, nil, String, 32)
|
33
|
+
cursor.bind_param(:raw, nil, OCI8::RAW, 16)
|
34
|
+
|
35
|
+
CHECK_TARGET.each do |raw, hex|
|
36
|
+
cursor[:hex] = hex
|
37
|
+
cursor.exec
|
38
|
+
assert_equal(raw, cursor[:raw])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def teardown
|
43
|
+
@conn.logoff
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'oci8'
|
3
|
+
require File.dirname(__FILE__) + '/config'
|
4
|
+
|
5
|
+
class TestBindString < Minitest::Test
|
6
|
+
def setup
|
7
|
+
@conn = get_oci8_connection
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
@conn.logoff
|
12
|
+
end
|
13
|
+
|
14
|
+
if OCI8.client_charset_name.include? 'UTF8'
|
15
|
+
|
16
|
+
def test_bind_string_as_nchar
|
17
|
+
if ['AL32UTF8', 'UTF8', 'ZHS32GB18030'].include? @conn.database_charset_name
|
18
|
+
warn "Skip test_bind_string_as_nchar. It needs Oracle server whose database chracter set is incompatible with unicode."
|
19
|
+
else
|
20
|
+
drop_table('test_table')
|
21
|
+
@conn.exec("CREATE TABLE test_table (ID NUMBER(5), V VARCHAR2(10), NV1 NVARCHAR2(10), NV2 NVARCHAR2(10))")
|
22
|
+
|
23
|
+
orig_prop = OCI8.properties[:bind_string_as_nchar]
|
24
|
+
begin
|
25
|
+
utf8_string = "a¡あ"
|
26
|
+
|
27
|
+
OCI8.properties[:bind_string_as_nchar] = false
|
28
|
+
@conn.exec("INSERT INTO test_table VALUES (1, N'#{utf8_string}', N'#{utf8_string}', :1)", utf8_string)
|
29
|
+
v, nv1, nv2 = @conn.select_one('select V, NV1, NV2 from test_table where ID = 1')
|
30
|
+
assert_not_equal(utf8_string, v) # Some UTF-8 chracters should be garbled.
|
31
|
+
assert_equal(utf8_string, nv1) # No garbled characters
|
32
|
+
assert_equal(v, nv2) # Garbled as VARCHAR2 column.
|
33
|
+
|
34
|
+
OCI8.properties[:bind_string_as_nchar] = true
|
35
|
+
@conn.exec("INSERT INTO test_table VALUES (2, N'#{utf8_string}', N'#{utf8_string}', :1)", utf8_string)
|
36
|
+
v, nv1, nv2 = @conn.select_one('select V, NV1, NV2 from test_table where ID = 2')
|
37
|
+
assert_not_equal(utf8_string, v) # Some UTF-8 chracters should be garbled.
|
38
|
+
assert_equal(utf8_string, nv1) # No garbled characters
|
39
|
+
assert_equal(nv1, nv2) # Same as NVARCHAR2.
|
40
|
+
|
41
|
+
@conn.commit
|
42
|
+
ensure
|
43
|
+
OCI8.properties[:bind_string_as_nchar] = orig_prop
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_length_semantics # This test needs to be revised.
|
49
|
+
orig_prop = OCI8.properties[:length_semantics]
|
50
|
+
begin
|
51
|
+
utf8_string = "a¡あ"
|
52
|
+
|
53
|
+
OCI8.properties[:length_semantics] = :byte
|
54
|
+
assert_equal(:byte, OCI8.properties[:length_semantics])
|
55
|
+
cursor = @conn.parse <<EOS
|
56
|
+
DECLARE
|
57
|
+
TMP VARCHAR2(6);
|
58
|
+
BEGIN
|
59
|
+
TMP := :in;
|
60
|
+
:out := TMP;
|
61
|
+
END;
|
62
|
+
EOS
|
63
|
+
cursor.bind_param(:in, utf8_string)
|
64
|
+
cursor.bind_param(:out, nil, String, 5)
|
65
|
+
begin
|
66
|
+
cursor.exec
|
67
|
+
rescue OCIError
|
68
|
+
assert_equal(6502, $!.code)
|
69
|
+
end
|
70
|
+
cursor.bind_param(:out, nil, String, 6)
|
71
|
+
cursor.exec
|
72
|
+
assert_equal(utf8_string, cursor[:out])
|
73
|
+
|
74
|
+
OCI8.properties[:length_semantics] = :char
|
75
|
+
assert_equal(:char, OCI8.properties[:length_semantics])
|
76
|
+
cursor = @conn.parse <<EOS
|
77
|
+
DECLARE
|
78
|
+
TMP VARCHAR2(6);
|
79
|
+
BEGIN
|
80
|
+
TMP := :in;
|
81
|
+
:out := TMP;
|
82
|
+
END;
|
83
|
+
EOS
|
84
|
+
cursor.bind_param(:in, utf8_string, String, 3)
|
85
|
+
cursor.bind_param(:out, nil, String, 2)
|
86
|
+
begin
|
87
|
+
cursor.exec
|
88
|
+
rescue OCIError
|
89
|
+
assert_equal(6502, $!.code)
|
90
|
+
end
|
91
|
+
cursor.bind_param(:out, nil, String, 3)
|
92
|
+
cursor.exec
|
93
|
+
assert_equal(utf8_string, cursor[:out])
|
94
|
+
ensure
|
95
|
+
OCI8.properties[:length_semantics] = orig_prop
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
else
|
100
|
+
|
101
|
+
def test_dummy
|
102
|
+
# to suppress "No tests were specified."
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|