ruby-staci 2.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +14 -0
  3. data/COPYING +30 -0
  4. data/COPYING_old +64 -0
  5. data/ChangeLog +3826 -0
  6. data/Makefile +92 -0
  7. data/NEWS +1194 -0
  8. data/README.md +66 -0
  9. data/dist-files +113 -0
  10. data/docs/bind-array-to-in_cond.md +38 -0
  11. data/docs/conflicts-local-connections-and-processes.md +98 -0
  12. data/docs/hanging-after-inactivity.md +63 -0
  13. data/docs/install-binary-package.md +44 -0
  14. data/docs/install-full-client.md +111 -0
  15. data/docs/install-instant-client.md +194 -0
  16. data/docs/install-on-osx.md +133 -0
  17. data/docs/ldap-auth-and-function-interposition.md +123 -0
  18. data/docs/number-type-mapping.md +79 -0
  19. data/docs/osx-install-dev-tools.png +0 -0
  20. data/docs/platform-specific-issues.md +164 -0
  21. data/docs/report-installation-issue.md +50 -0
  22. data/docs/timeout-parameters.md +94 -0
  23. data/ext/oci8/.document +18 -0
  24. data/ext/oci8/MANIFEST +18 -0
  25. data/ext/oci8/apiwrap.c.tmpl +178 -0
  26. data/ext/oci8/apiwrap.h.tmpl +61 -0
  27. data/ext/oci8/apiwrap.rb +96 -0
  28. data/ext/oci8/apiwrap.yml +1322 -0
  29. data/ext/oci8/attr.c +57 -0
  30. data/ext/oci8/bind.c +838 -0
  31. data/ext/oci8/connection_pool.c +216 -0
  32. data/ext/oci8/encoding.c +196 -0
  33. data/ext/oci8/env.c +139 -0
  34. data/ext/oci8/error.c +385 -0
  35. data/ext/oci8/extconf.rb +219 -0
  36. data/ext/oci8/hook_funcs.c +407 -0
  37. data/ext/oci8/lob.c +1278 -0
  38. data/ext/oci8/metadata.c +279 -0
  39. data/ext/oci8/object.c +919 -0
  40. data/ext/oci8/oci8.c +1058 -0
  41. data/ext/oci8/oci8.h +556 -0
  42. data/ext/oci8/oci8lib.c +704 -0
  43. data/ext/oci8/ocidatetime.c +506 -0
  44. data/ext/oci8/ocihandle.c +852 -0
  45. data/ext/oci8/ocinumber.c +1922 -0
  46. data/ext/oci8/oraconf.rb +1145 -0
  47. data/ext/oci8/oradate.c +670 -0
  48. data/ext/oci8/oranumber_util.c +352 -0
  49. data/ext/oci8/oranumber_util.h +24 -0
  50. data/ext/oci8/plthook.h +66 -0
  51. data/ext/oci8/plthook_elf.c +702 -0
  52. data/ext/oci8/plthook_osx.c +505 -0
  53. data/ext/oci8/plthook_win32.c +391 -0
  54. data/ext/oci8/post-config.rb +5 -0
  55. data/ext/oci8/stmt.c +448 -0
  56. data/ext/oci8/thread_util.c +81 -0
  57. data/ext/oci8/thread_util.h +18 -0
  58. data/ext/oci8/util.c +71 -0
  59. data/ext/oci8/win32.c +117 -0
  60. data/lib/.document +1 -0
  61. data/lib/dbd/STACI.rb +591 -0
  62. data/lib/oci8/.document +8 -0
  63. data/lib/oci8/bindtype.rb +333 -0
  64. data/lib/oci8/check_load_error.rb +146 -0
  65. data/lib/oci8/compat.rb +117 -0
  66. data/lib/oci8/connection_pool.rb +179 -0
  67. data/lib/oci8/cursor.rb +605 -0
  68. data/lib/oci8/datetime.rb +605 -0
  69. data/lib/oci8/encoding-init.rb +45 -0
  70. data/lib/oci8/encoding.yml +537 -0
  71. data/lib/oci8/metadata.rb +2148 -0
  72. data/lib/oci8/object.rb +641 -0
  73. data/lib/oci8/oci8.rb +756 -0
  74. data/lib/oci8/ocihandle.rb +591 -0
  75. data/lib/oci8/oracle_version.rb +153 -0
  76. data/lib/oci8/properties.rb +196 -0
  77. data/lib/oci8/version.rb +3 -0
  78. data/lib/ruby-staci.rb +1 -0
  79. data/lib/staci.rb +190 -0
  80. data/metaconfig +142 -0
  81. data/pre-distclean.rb +7 -0
  82. data/ruby-aci.gemspec +83 -0
  83. data/setup.rb +1342 -0
  84. data/test/README.md +37 -0
  85. data/test/config.rb +201 -0
  86. data/test/setup_test_object.sql +199 -0
  87. data/test/setup_test_package.sql +59 -0
  88. data/test/test_all.rb +56 -0
  89. data/test/test_appinfo.rb +62 -0
  90. data/test/test_array_dml.rb +333 -0
  91. data/test/test_bind_array.rb +70 -0
  92. data/test/test_bind_boolean.rb +99 -0
  93. data/test/test_bind_integer.rb +47 -0
  94. data/test/test_bind_raw.rb +45 -0
  95. data/test/test_bind_string.rb +105 -0
  96. data/test/test_bind_time.rb +177 -0
  97. data/test/test_break.rb +124 -0
  98. data/test/test_clob.rb +86 -0
  99. data/test/test_connection_pool.rb +124 -0
  100. data/test/test_connstr.rb +220 -0
  101. data/test/test_datetime.rb +585 -0
  102. data/test/test_dbi.rb +365 -0
  103. data/test/test_dbi_clob.rb +53 -0
  104. data/test/test_encoding.rb +103 -0
  105. data/test/test_error.rb +87 -0
  106. data/test/test_metadata.rb +2674 -0
  107. data/test/test_object.rb +546 -0
  108. data/test/test_oci8.rb +624 -0
  109. data/test/test_oracle_version.rb +68 -0
  110. data/test/test_oradate.rb +255 -0
  111. data/test/test_oranumber.rb +786 -0
  112. data/test/test_package_type.rb +981 -0
  113. data/test/test_properties.rb +17 -0
  114. data/test/test_rowid.rb +32 -0
  115. metadata +158 -0
@@ -0,0 +1,333 @@
1
+ require 'staci'
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 * 11111
60
+ bignum_arr << i * 10000
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, 00, 00, 00)
103
+ assert_equal(tm, rv[3])
104
+ assert_equal(i * 11111, rv[4])
105
+ assert_equal(i * 10000, rv[5])
106
+ tm = Time.local(2000 + i, 12, 24, 23, 59, 59)
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_raises(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
+ cursor.exec_array
158
+ cursor.max_array_size = 2
159
+ assert_raises(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
+ 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_raises(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,70 @@
1
+ require 'staci'
2
+ require File.dirname(__FILE__) + '/config'
3
+
4
+ class TestBindArray < Minitest::Test
5
+
6
+ def test_bind_array_names
7
+ assert_equal(":id_0", STACI::in_cond(:id, []).names)
8
+ assert_equal(":id_0", STACI::in_cond(:id, [1]).names)
9
+ assert_equal(":id_0, :id_1", STACI::in_cond(:id, [1, 2]).names)
10
+ assert_equal(":id_0, :id_1, :id_2", STACI::in_cond(:id, [1, 2, 3]).names)
11
+ end
12
+
13
+ def test_bind_array_values
14
+ assert_equal([[nil, String, nil]], STACI::in_cond(:id, []).values)
15
+ assert_equal([[1, nil, nil]], STACI::in_cond(:id, [1]).values)
16
+ assert_equal([[1, nil, nil], [2, nil, nil]], STACI::in_cond(:id, [1, 2]).values)
17
+ assert_equal([[1, nil, nil], [2, nil, nil], [3, nil, nil]], STACI::in_cond(:id, [1, 2, 3]).values)
18
+ end
19
+
20
+ def test_bind_array_values_containg_nil
21
+ assert_equal([[nil, String]], STACI::in_cond(:id, [nil]).values)
22
+ assert_equal([[nil, Fixnum], [2, nil, nil], [3, nil, nil]], STACI::in_cond(:id, [nil, 2, 3]).values)
23
+ assert_equal([[1, nil, nil], [nil, Fixnum], [3, nil, nil]], STACI::in_cond(:id, [1, nil, 3]).values)
24
+ end
25
+
26
+ def test_bind_array_values_with_type
27
+ assert_equal([[nil, Integer, nil]], STACI::in_cond(:id, [], Integer).values)
28
+ assert_equal([[1, Integer, nil]], STACI::in_cond(:id, [1], Integer).values)
29
+ assert_equal([[1, Integer, nil], [2, Integer, nil]], STACI::in_cond(:id, [1, 2], Integer).values)
30
+ assert_equal([[1, Integer, nil], [2, Integer, nil], [3, Integer, nil]], STACI::in_cond(:id, [1, 2, 3], Integer).values)
31
+ assert_equal([[nil, Integer, nil], [2, Integer, nil], [3, Integer, nil]], STACI::in_cond(:id, [nil, 2, 3], Integer).values)
32
+ assert_equal([[1, Integer, nil], [nil, Integer, nil], [3, Integer, nil]], STACI::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 = STACI::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 'staci'
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 'staci'
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 'staci'
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, STACI::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, STACI::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 'staci'
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 STACI.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 = STACI.properties[:bind_string_as_nchar]
24
+ begin
25
+ utf8_string = "a¡あ"
26
+
27
+ STACI.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
+ STACI.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
+ STACI.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 = STACI.properties[:length_semantics]
50
+ begin
51
+ utf8_string = "a¡あ"
52
+
53
+ STACI.properties[:length_semantics] = :byte
54
+ assert_equal(:byte, STACI.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
+ STACI.properties[:length_semantics] = :char
75
+ assert_equal(:char, STACI.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
+ STACI.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