ruby-oci8 2.1.5.1-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +17 -0
- data/COPYING +30 -0
- data/COPYING_old +64 -0
- data/ChangeLog +2779 -0
- data/Makefile +92 -0
- data/NEWS +660 -0
- data/README.md +43 -0
- data/VERSION +1 -0
- data/dist-files +91 -0
- data/docs/install-binary-package.md +40 -0
- data/docs/install-full-client.md +116 -0
- data/docs/install-instant-client.md +167 -0
- data/docs/platform-specific-issues.md +197 -0
- data/docs/report-installation-issue.md +50 -0
- data/lib/.document +1 -0
- data/lib/dbd/OCI8.rb +591 -0
- data/lib/oci8.rb +147 -0
- data/lib/oci8.rb.in +147 -0
- data/lib/oci8/.document +8 -0
- data/lib/oci8/bindtype.rb +350 -0
- data/lib/oci8/compat.rb +113 -0
- data/lib/oci8/connection_pool.rb +108 -0
- data/lib/oci8/cursor.rb +564 -0
- data/lib/oci8/datetime.rb +605 -0
- data/lib/oci8/encoding-init.rb +79 -0
- data/lib/oci8/encoding.yml +537 -0
- data/lib/oci8/metadata.rb +2092 -0
- data/lib/oci8/object.rb +605 -0
- data/lib/oci8/oci8.rb +560 -0
- data/lib/oci8/ocihandle.rb +607 -0
- data/lib/oci8/oracle_version.rb +143 -0
- data/lib/oci8/properties.rb +134 -0
- data/lib/oci8lib_200.so +0 -0
- data/metaconfig +142 -0
- data/pre-distclean.rb +7 -0
- data/ruby-oci8.gemspec +80 -0
- data/setup.rb +1333 -0
- data/test/README +42 -0
- data/test/config.rb +184 -0
- data/test/setup_test_object.sql +171 -0
- data/test/test_all.rb +54 -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_string.rb +106 -0
- data/test/test_bind_time.rb +178 -0
- data/test/test_break.rb +124 -0
- data/test/test_clob.rb +98 -0
- data/test/test_connection_pool.rb +125 -0
- data/test/test_connstr.rb +81 -0
- data/test/test_datetime.rb +581 -0
- data/test/test_dbi.rb +366 -0
- data/test/test_dbi_clob.rb +53 -0
- data/test/test_encoding.rb +104 -0
- data/test/test_error.rb +88 -0
- data/test/test_metadata.rb +1485 -0
- data/test/test_object.rb +462 -0
- data/test/test_oci8.rb +489 -0
- data/test/test_oracle_version.rb +70 -0
- data/test/test_oradate.rb +256 -0
- data/test/test_oranumber.rb +787 -0
- data/test/test_rowid.rb +33 -0
- metadata +109 -0
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'oci8'
|
2
|
+
require 'test/unit'
|
3
|
+
require File.dirname(__FILE__) + '/config'
|
4
|
+
|
5
|
+
class TestAppInfo < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@conn = get_oci8_connection
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_set_client_identifier
|
12
|
+
# set client_id
|
13
|
+
client_id = "ruby-oci8:#{Process.pid()}"
|
14
|
+
@conn.client_identifier = client_id
|
15
|
+
assert_equal(client_id, @conn.select_one("SELECT SYS_CONTEXT('USERENV', 'CLIENT_IDENTIFIER') FROM DUAL")[0]);
|
16
|
+
# check the first character
|
17
|
+
assert_raise ArgumentError do
|
18
|
+
@conn.client_identifier = ':bad_identifier'
|
19
|
+
end
|
20
|
+
|
21
|
+
# clear client_id
|
22
|
+
@conn.client_identifier = nil
|
23
|
+
assert_nil(@conn.select_one("SELECT SYS_CONTEXT('USERENV', 'CLIENT_IDENTIFIER') FROM DUAL")[0]);
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_set_module
|
27
|
+
# FIXME: check again after upgrading Oracle 9.2 to 9.2.0.4.
|
28
|
+
return if @conn.oracle_server_version < OCI8::ORAVER_10_1
|
29
|
+
|
30
|
+
# set module
|
31
|
+
@conn.module = 'ruby-oci8'
|
32
|
+
assert_equal('ruby-oci8', @conn.select_one("SELECT SYS_CONTEXT('USERENV', 'MODULE') FROM DUAL")[0]);
|
33
|
+
# clear module
|
34
|
+
@conn.module = nil
|
35
|
+
assert_nil(@conn.select_one("SELECT SYS_CONTEXT('USERENV', 'MODULE') FROM DUAL")[0]);
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_set_action
|
39
|
+
# FIXME: check again after upgrading Oracle 9.2 to 9.2.0.4.
|
40
|
+
return if @conn.oracle_server_version < OCI8::ORAVER_10_1
|
41
|
+
|
42
|
+
# set action
|
43
|
+
@conn.action = 'test_set_action'
|
44
|
+
assert_equal('test_set_action', @conn.select_one("SELECT SYS_CONTEXT('USERENV', 'ACTION') FROM DUAL")[0]);
|
45
|
+
# clear action
|
46
|
+
@conn.action = nil
|
47
|
+
assert_nil(@conn.select_one("SELECT SYS_CONTEXT('USERENV', 'ACTION') FROM DUAL")[0]);
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_set_client_info
|
51
|
+
# set client_info
|
52
|
+
client_info = "ruby-oci8:#{Process.pid()}"
|
53
|
+
@conn.client_info = client_info
|
54
|
+
assert_equal(client_info, @conn.select_one("SELECT SYS_CONTEXT('USERENV', 'CLIENT_INFO') FROM DUAL")[0]);
|
55
|
+
# clear client_info
|
56
|
+
@conn.client_info = nil
|
57
|
+
assert_nil(@conn.select_one("SELECT SYS_CONTEXT('USERENV', 'CLIENT_INFO') FROM DUAL")[0]);
|
58
|
+
end
|
59
|
+
|
60
|
+
def teardown
|
61
|
+
@conn.logoff
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,333 @@
|
|
1
|
+
require 'oci8'
|
2
|
+
require 'test/unit'
|
3
|
+
require File.dirname(__FILE__) + '/config'
|
4
|
+
|
5
|
+
class TestArrayDML < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@conn = get_oci8_connection
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
@conn.logoff
|
12
|
+
end
|
13
|
+
|
14
|
+
# test inserting arrays with different data types
|
15
|
+
# including char, varchar2, number, date and so on
|
16
|
+
def test_array_insert1
|
17
|
+
drop_table('test_table')
|
18
|
+
sql = <<-EOS
|
19
|
+
CREATE TABLE test_table
|
20
|
+
(C CHAR(10) NOT NULL,
|
21
|
+
V VARCHAR2(20),
|
22
|
+
N NUMBER(10, 2),
|
23
|
+
D DATE,
|
24
|
+
INT NUMBER(30),
|
25
|
+
BIGNUM NUMBER(30),
|
26
|
+
T TIMESTAMP)
|
27
|
+
STORAGE (
|
28
|
+
INITIAL 4k
|
29
|
+
NEXT 4k
|
30
|
+
MINEXTENTS 1
|
31
|
+
MAXEXTENTS UNLIMITED
|
32
|
+
PCTINCREASE 0)
|
33
|
+
EOS
|
34
|
+
@conn.exec(sql)
|
35
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:C, :V, :N, :D, :INT, :BIGNUM, :T)")
|
36
|
+
max_array_size = 3
|
37
|
+
cursor.max_array_size= max_array_size
|
38
|
+
|
39
|
+
cursor.bind_param_array(1, nil, String)
|
40
|
+
cursor.bind_param_array(2, nil ,String)
|
41
|
+
cursor.bind_param_array(3, nil, Fixnum)
|
42
|
+
cursor.bind_param_array(4, nil, OraDate)
|
43
|
+
cursor.bind_param_array(5, nil, Integer)
|
44
|
+
cursor.bind_param_array(6, nil, Bignum)
|
45
|
+
cursor.bind_param_array(7, nil, DateTime)
|
46
|
+
|
47
|
+
c_arr = Array.new
|
48
|
+
v_arr = Array.new
|
49
|
+
n_arr = Array.new
|
50
|
+
d_arr = Array.new
|
51
|
+
int_arr = Array.new
|
52
|
+
bignum_arr = Array.new
|
53
|
+
t_arr = Array.new
|
54
|
+
|
55
|
+
1.upto(30) do |i|
|
56
|
+
c_arr << format("%10d", i * 10)
|
57
|
+
v_arr << i.to_s
|
58
|
+
n_arr << i
|
59
|
+
d_arr << OraDate.new(2000 + i, 12, 24, 23, 59, 59)
|
60
|
+
int_arr << i * 11111111111
|
61
|
+
bignum_arr << i * 10000000000
|
62
|
+
t_arr << DateTime.new(2000 + i, 12, 24, 23, 59, 59)
|
63
|
+
|
64
|
+
if i%max_array_size == 0
|
65
|
+
cursor[1] = c_arr
|
66
|
+
cursor[2] = v_arr
|
67
|
+
cursor[3] = n_arr
|
68
|
+
cursor[4] = d_arr
|
69
|
+
cursor[5] = int_arr
|
70
|
+
cursor[6] = bignum_arr
|
71
|
+
cursor[7] = t_arr
|
72
|
+
|
73
|
+
r = cursor.exec_array
|
74
|
+
assert_equal(max_array_size, r)
|
75
|
+
assert_equal(c_arr, cursor[1])
|
76
|
+
assert_equal(v_arr, cursor[2])
|
77
|
+
assert_equal(n_arr, cursor[3])
|
78
|
+
assert_equal(d_arr, cursor[4])
|
79
|
+
assert_equal(int_arr, cursor[5])
|
80
|
+
assert_equal(bignum_arr, cursor[6])
|
81
|
+
assert_equal(t_arr, cursor[7])
|
82
|
+
c_arr.clear
|
83
|
+
v_arr.clear
|
84
|
+
n_arr.clear
|
85
|
+
d_arr.clear
|
86
|
+
int_arr.clear
|
87
|
+
bignum_arr.clear
|
88
|
+
t_arr.clear
|
89
|
+
end
|
90
|
+
end
|
91
|
+
cursor.close
|
92
|
+
|
93
|
+
cursor = @conn.parse("SELECT * FROM test_table ORDER BY c")
|
94
|
+
cursor.define(5, Integer)
|
95
|
+
cursor.define(6, Bignum)
|
96
|
+
cursor.exec
|
97
|
+
assert_equal(["C","V","N","D","INT","BIGNUM","T"], cursor.get_col_names)
|
98
|
+
1.upto(30) do |i|
|
99
|
+
rv = cursor.fetch
|
100
|
+
assert_equal(format("%10d", i * 10), rv[0])
|
101
|
+
assert_equal(i.to_s, rv[1])
|
102
|
+
assert_equal(i, rv[2])
|
103
|
+
tm = Time.local(2000 + i, 12, 24, 23, 59, 59)
|
104
|
+
assert_equal(tm, rv[3])
|
105
|
+
assert_equal(i * 11111111111, rv[4])
|
106
|
+
assert_equal(i * 10000000000, rv[5])
|
107
|
+
assert_equal(tm, rv[6])
|
108
|
+
end
|
109
|
+
assert_nil(cursor.fetch)
|
110
|
+
drop_table('test_table')
|
111
|
+
end
|
112
|
+
|
113
|
+
# Raise error when binding arrays are not the same size
|
114
|
+
def test_array_insert2
|
115
|
+
drop_table('test_table')
|
116
|
+
sql = <<-EOS
|
117
|
+
CREATE TABLE test_table
|
118
|
+
(N NUMBER(10, 2) NOT NULL,
|
119
|
+
V VARCHAR(20))
|
120
|
+
EOS
|
121
|
+
@conn.exec(sql)
|
122
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:N, :V)")
|
123
|
+
max_array_size = 10
|
124
|
+
cursor.max_array_size = max_array_size
|
125
|
+
cursor.bind_param_array(1, nil, Fixnum)
|
126
|
+
cursor.bind_param_array(2, nil, String)
|
127
|
+
n_arr = Array.new
|
128
|
+
v_arr = Array.new
|
129
|
+
1.upto(max_array_size) do |i|
|
130
|
+
n_arr << i
|
131
|
+
v_arr << i.to_s if i != max_array_size
|
132
|
+
end
|
133
|
+
cursor[1] = n_arr
|
134
|
+
assert_raise(RuntimeError) { cursor[2] = v_arr }
|
135
|
+
cursor.close
|
136
|
+
|
137
|
+
drop_table('test_table')
|
138
|
+
end
|
139
|
+
|
140
|
+
# All binds are clear from cursor after calling "max_array_size=",
|
141
|
+
# in that case, you have to re-bind the array parameters
|
142
|
+
# otherwise, an error will be raised.
|
143
|
+
def test_array_insert3
|
144
|
+
drop_table('test_table')
|
145
|
+
sql = <<-EOS
|
146
|
+
CREATE TABLE test_table
|
147
|
+
(N NUMBER(10, 2) NOT NULL,
|
148
|
+
V VARCHAR(20),
|
149
|
+
T TIMESTAMP)
|
150
|
+
EOS
|
151
|
+
@conn.exec(sql)
|
152
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:N, :V, :T)")
|
153
|
+
cursor.max_array_size = 3
|
154
|
+
cursor.bind_param_array(1, [1, 2, 3])
|
155
|
+
cursor.bind_param_array(2, ['happy', 'new', 'year'])
|
156
|
+
cursor.bind_param_array(3, [Time.gm(1990,1,1), Time.gm(2000,1,1), Time.gm(2010,1,1)])
|
157
|
+
assert_nothing_raised() { cursor.exec_array }
|
158
|
+
cursor.max_array_size = 2
|
159
|
+
assert_raise(RuntimeError) { cursor.exec_array }
|
160
|
+
drop_table('test_table')
|
161
|
+
end
|
162
|
+
|
163
|
+
# The size of binding arrays are not required to be same as max_array_size. The
|
164
|
+
# only requirement is that they should be the same size, and the size will be
|
165
|
+
# used as execution count for OCIStmtExecute.
|
166
|
+
def test_array_insert4
|
167
|
+
drop_table('test_table')
|
168
|
+
sql = <<-EOS
|
169
|
+
CREATE TABLE test_table
|
170
|
+
(N NUMBER(10, 2) NOT NULL,
|
171
|
+
V VARCHAR(20))
|
172
|
+
EOS
|
173
|
+
@conn.exec(sql)
|
174
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:N, :V)")
|
175
|
+
max_array_size = 4
|
176
|
+
cursor.max_array_size = max_array_size
|
177
|
+
cursor.bind_param_array(1, nil, Fixnum)
|
178
|
+
cursor.bind_param_array(2, nil, String)
|
179
|
+
n_arr = Array.new
|
180
|
+
v_arr = Array.new
|
181
|
+
1.upto( max_array_size - 1 ) do |i|
|
182
|
+
n_arr << i
|
183
|
+
v_arr << i.to_s
|
184
|
+
end
|
185
|
+
cursor[1] = n_arr
|
186
|
+
cursor[2] = v_arr
|
187
|
+
assert_nothing_raised() { cursor.exec_array }
|
188
|
+
cursor.close
|
189
|
+
|
190
|
+
cursor = @conn.parse("SELECT * FROM test_table ORDER BY N")
|
191
|
+
cursor.exec
|
192
|
+
1.upto( max_array_size - 1 ) do |i|
|
193
|
+
rv = cursor.fetch
|
194
|
+
assert_equal(i, rv[0])
|
195
|
+
assert_equal(i.to_s, rv[1])
|
196
|
+
end
|
197
|
+
assert_nil(cursor.fetch)
|
198
|
+
cursor.close
|
199
|
+
drop_table('test_table')
|
200
|
+
end
|
201
|
+
|
202
|
+
# Inserting "nil" elements with array dml raises an error
|
203
|
+
def test_array_insert5
|
204
|
+
drop_table('test_table')
|
205
|
+
sql = <<-EOS
|
206
|
+
CREATE TABLE test_table
|
207
|
+
(N NUMBER(10, 2),
|
208
|
+
V VARCHAR(20))
|
209
|
+
EOS
|
210
|
+
@conn.exec(sql)
|
211
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:N, :V)")
|
212
|
+
max_array_size = 3
|
213
|
+
cursor.max_array_size = max_array_size
|
214
|
+
cursor.bind_param_array(1, nil, Fixnum)
|
215
|
+
cursor.bind_param_array(2, nil, String)
|
216
|
+
assert_raise(RuntimeError) { cursor.exec_array }
|
217
|
+
cursor.close
|
218
|
+
drop_table('test_table')
|
219
|
+
end
|
220
|
+
|
221
|
+
# delete with array bindings
|
222
|
+
def test_array_delete
|
223
|
+
drop_table('test_table')
|
224
|
+
sql = <<-EOS
|
225
|
+
CREATE TABLE test_table
|
226
|
+
(N NUMBER(10, 2),
|
227
|
+
V VARCHAR(20))
|
228
|
+
EOS
|
229
|
+
@conn.exec(sql)
|
230
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:N, :V)")
|
231
|
+
max_array_size = 10
|
232
|
+
cursor.max_array_size = max_array_size
|
233
|
+
n_arr = Array.new
|
234
|
+
v_arr = Array.new
|
235
|
+
1.upto( max_array_size) do |i|
|
236
|
+
n_arr << i
|
237
|
+
v_arr << i.to_s
|
238
|
+
end
|
239
|
+
cursor.bind_param_array(1, nil, Fixnum)
|
240
|
+
cursor.bind_param_array(2, nil, String)
|
241
|
+
cursor[1] = n_arr
|
242
|
+
cursor[2] = v_arr
|
243
|
+
cursor.exec_array
|
244
|
+
cursor.close
|
245
|
+
|
246
|
+
cursor = @conn.parse("DELETE FROM test_table WHERE N=:1")
|
247
|
+
cursor.max_array_size = max_array_size
|
248
|
+
delete_arr = Array.new
|
249
|
+
1.upto(max_array_size) do |i|
|
250
|
+
if i%2 == 0
|
251
|
+
delete_arr << i
|
252
|
+
end
|
253
|
+
end
|
254
|
+
cursor.bind_param_array(1, nil, Fixnum)
|
255
|
+
cursor[1] = delete_arr
|
256
|
+
cursor.exec_array
|
257
|
+
cursor.close
|
258
|
+
|
259
|
+
cursor = @conn.parse("SELECT * FROM test_table ORDER BY N")
|
260
|
+
cursor.exec
|
261
|
+
1.upto( max_array_size ) do |i|
|
262
|
+
if i%2 != 0
|
263
|
+
rv = cursor.fetch
|
264
|
+
assert_equal(rv[0], i)
|
265
|
+
assert_equal(rv[1], i.to_s)
|
266
|
+
end
|
267
|
+
end
|
268
|
+
assert_nil(cursor.fetch)
|
269
|
+
cursor.close
|
270
|
+
|
271
|
+
drop_table('test_table')
|
272
|
+
end
|
273
|
+
|
274
|
+
# update with array bindings
|
275
|
+
def test_array_update
|
276
|
+
drop_table('test_table')
|
277
|
+
sql = <<-EOS
|
278
|
+
CREATE TABLE test_table
|
279
|
+
(N NUMBER(10, 2),
|
280
|
+
V VARCHAR(20))
|
281
|
+
EOS
|
282
|
+
@conn.exec(sql)
|
283
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:N, :V)")
|
284
|
+
max_array_size = 10
|
285
|
+
cursor.max_array_size = max_array_size
|
286
|
+
n_arr = Array.new
|
287
|
+
v_arr = Array.new
|
288
|
+
1.upto( max_array_size) do |i|
|
289
|
+
n_arr << i
|
290
|
+
v_arr << i.to_s
|
291
|
+
end
|
292
|
+
cursor.bind_param_array(1, nil, Fixnum)
|
293
|
+
cursor.bind_param_array(2, nil, String)
|
294
|
+
cursor[1] = n_arr
|
295
|
+
cursor[2] = v_arr
|
296
|
+
cursor.exec_array
|
297
|
+
cursor.close
|
298
|
+
|
299
|
+
cursor = @conn.parse("UPDATE test_table SET V=:1 WHERE N=:2")
|
300
|
+
cursor.max_array_size = max_array_size
|
301
|
+
update_arr = Array.new
|
302
|
+
update_v_arr = Array.new
|
303
|
+
1.upto(max_array_size) do |i|
|
304
|
+
if i%2 == 0
|
305
|
+
update_arr << i
|
306
|
+
update_v_arr << (i * 10).to_s
|
307
|
+
end
|
308
|
+
end
|
309
|
+
cursor.bind_param_array(1, nil, String)
|
310
|
+
cursor.bind_param_array(2, nil, Fixnum)
|
311
|
+
cursor[1] = update_v_arr
|
312
|
+
cursor[2] = update_arr
|
313
|
+
cursor.exec_array
|
314
|
+
cursor.close
|
315
|
+
|
316
|
+
cursor = @conn.parse("SELECT * FROM test_table ORDER BY N")
|
317
|
+
cursor.exec
|
318
|
+
1.upto( max_array_size ) do |i|
|
319
|
+
rv = cursor.fetch
|
320
|
+
if i%2 != 0
|
321
|
+
assert_equal(rv[0], i)
|
322
|
+
assert_equal(rv[1], i.to_s)
|
323
|
+
else
|
324
|
+
assert_equal(rv[0], i)
|
325
|
+
assert_equal(rv[1], (i * 10).to_s)
|
326
|
+
end
|
327
|
+
end
|
328
|
+
assert_nil(cursor.fetch)
|
329
|
+
|
330
|
+
cursor.close
|
331
|
+
drop_table('test_table')
|
332
|
+
end
|
333
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Low-level API
|
2
|
+
require 'oci8'
|
3
|
+
require 'test/unit'
|
4
|
+
require File.dirname(__FILE__) + '/config'
|
5
|
+
|
6
|
+
class TestBindRaw < Test::Unit::TestCase
|
7
|
+
CHECK_TARGET = [
|
8
|
+
["0123456789:;<=>?", "303132333435363738393A3B3C3D3E3F"],
|
9
|
+
["@ABCDEFGHIJKLMNO", "404142434445464748494A4B4C4D4E4F"],
|
10
|
+
["PQRSTUVWXYZ[\\]^_", "505152535455565758595A5B5C5D5E5F"],
|
11
|
+
["`abcdefghijklmno", "606162636465666768696A6B6C6D6E6F"],
|
12
|
+
["pqrstuvwxyz{|}~", "707172737475767778797A7B7C7D7E"],
|
13
|
+
]
|
14
|
+
|
15
|
+
def setup
|
16
|
+
@conn = get_oci8_connection()
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_set_raw
|
20
|
+
cursor = @conn.parse("BEGIN :hex := RAWTOHEX(:raw); END;")
|
21
|
+
cursor.bind_param(:raw, nil, OCI8::RAW, 16)
|
22
|
+
cursor.bind_param(:hex, nil, String, 32)
|
23
|
+
|
24
|
+
CHECK_TARGET.each do |raw, hex|
|
25
|
+
cursor[:raw] = raw
|
26
|
+
cursor.exec
|
27
|
+
assert_equal(hex, cursor[:hex])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_get_raw
|
32
|
+
cursor = @conn.parse("BEGIN :raw := HEXTORAW(:hex); END;")
|
33
|
+
cursor.bind_param(:hex, nil, String, 32)
|
34
|
+
cursor.bind_param(:raw, nil, OCI8::RAW, 16)
|
35
|
+
|
36
|
+
CHECK_TARGET.each do |raw, hex|
|
37
|
+
cursor[:hex] = hex
|
38
|
+
cursor.exec
|
39
|
+
assert_equal(raw, cursor[:raw])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def teardown
|
44
|
+
@conn.logoff
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'oci8'
|
3
|
+
require 'test/unit'
|
4
|
+
require File.dirname(__FILE__) + '/config'
|
5
|
+
|
6
|
+
class TestBindString < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@conn = get_oci8_connection
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
@conn.logoff
|
13
|
+
end
|
14
|
+
|
15
|
+
if OCI8.client_charset_name.include? 'UTF8'
|
16
|
+
|
17
|
+
def test_bind_string_as_nchar
|
18
|
+
if ['AL32UTF8', 'UTF8', 'ZHS32GB18030'].include? @conn.database_charset_name
|
19
|
+
warn "Skip test_bind_string_as_nchar. It needs Oracle server whose database chracter set is incompatible with unicode."
|
20
|
+
else
|
21
|
+
drop_table('test_table')
|
22
|
+
@conn.exec("CREATE TABLE test_table (ID NUMBER(5), V VARCHAR2(10), NV1 NVARCHAR2(10), NV2 NVARCHAR2(10))")
|
23
|
+
|
24
|
+
orig_prop = OCI8.properties[:bind_string_as_nchar]
|
25
|
+
begin
|
26
|
+
utf8_string = "a¡あ"
|
27
|
+
|
28
|
+
OCI8.properties[:bind_string_as_nchar] = false
|
29
|
+
@conn.exec("INSERT INTO test_table VALUES (1, N'#{utf8_string}', N'#{utf8_string}', :1)", utf8_string)
|
30
|
+
v, nv1, nv2 = @conn.select_one('select V, NV1, NV2 from test_table where ID = 1')
|
31
|
+
assert_not_equal(utf8_string, v) # Some UTF-8 chracters should be garbled.
|
32
|
+
assert_equal(utf8_string, nv1) # No garbled characters
|
33
|
+
assert_equal(v, nv2) # Garbled as VARCHAR2 column.
|
34
|
+
|
35
|
+
OCI8.properties[:bind_string_as_nchar] = true
|
36
|
+
@conn.exec("INSERT INTO test_table VALUES (2, N'#{utf8_string}', N'#{utf8_string}', :1)", utf8_string)
|
37
|
+
v, nv1, nv2 = @conn.select_one('select V, NV1, NV2 from test_table where ID = 2')
|
38
|
+
assert_not_equal(utf8_string, v) # Some UTF-8 chracters should be garbled.
|
39
|
+
assert_equal(utf8_string, nv1) # No garbled characters
|
40
|
+
assert_equal(nv1, nv2) # Same as NVARCHAR2.
|
41
|
+
|
42
|
+
@conn.commit
|
43
|
+
ensure
|
44
|
+
OCI8.properties[:bind_string_as_nchar] = orig_prop
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_length_semantics # This test needs to be revised.
|
50
|
+
orig_prop = OCI8.properties[:length_semantics]
|
51
|
+
begin
|
52
|
+
utf8_string = "a¡あ"
|
53
|
+
|
54
|
+
OCI8.properties[:length_semantics] = :byte
|
55
|
+
assert_equal(:byte, OCI8.properties[:length_semantics])
|
56
|
+
cursor = @conn.parse <<EOS
|
57
|
+
DECLARE
|
58
|
+
TMP VARCHAR2(6);
|
59
|
+
BEGIN
|
60
|
+
TMP := :in;
|
61
|
+
:out := TMP;
|
62
|
+
END;
|
63
|
+
EOS
|
64
|
+
cursor.bind_param(:in, utf8_string)
|
65
|
+
cursor.bind_param(:out, nil, String, 5)
|
66
|
+
begin
|
67
|
+
cursor.exec
|
68
|
+
rescue OCIError
|
69
|
+
assert_equal(6502, $!.code)
|
70
|
+
end
|
71
|
+
cursor.bind_param(:out, nil, String, 6)
|
72
|
+
cursor.exec
|
73
|
+
assert_equal(utf8_string, cursor[:out])
|
74
|
+
|
75
|
+
OCI8.properties[:length_semantics] = :char
|
76
|
+
assert_equal(:char, OCI8.properties[:length_semantics])
|
77
|
+
cursor = @conn.parse <<EOS
|
78
|
+
DECLARE
|
79
|
+
TMP VARCHAR2(6);
|
80
|
+
BEGIN
|
81
|
+
TMP := :in;
|
82
|
+
:out := TMP;
|
83
|
+
END;
|
84
|
+
EOS
|
85
|
+
cursor.bind_param(:in, utf8_string, String, 3)
|
86
|
+
cursor.bind_param(:out, nil, String, 2)
|
87
|
+
begin
|
88
|
+
cursor.exec
|
89
|
+
rescue OCIError
|
90
|
+
assert_equal(6502, $!.code)
|
91
|
+
end
|
92
|
+
cursor.bind_param(:out, nil, String, 3)
|
93
|
+
cursor.exec
|
94
|
+
assert_equal(utf8_string, cursor[:out])
|
95
|
+
ensure
|
96
|
+
OCI8.properties[:length_semantics] = orig_prop
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
else
|
101
|
+
|
102
|
+
def test_dummy
|
103
|
+
# to suppress "No tests were specified."
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|