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.
Files changed (78) 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 +1209 -0
  8. data/README.md +66 -0
  9. data/dist-files +112 -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 +46 -0
  17. data/docs/ldap-auth-and-function-interposition.md +123 -0
  18. data/docs/number-type-mapping.md +79 -0
  19. data/docs/platform-specific-issues.md +164 -0
  20. data/docs/report-installation-issue.md +50 -0
  21. data/docs/timeout-parameters.md +94 -0
  22. data/lib/.document +1 -0
  23. data/lib/dbd/OCI8.rb +591 -0
  24. data/lib/oci8/.document +8 -0
  25. data/lib/oci8/bindtype.rb +333 -0
  26. data/lib/oci8/check_load_error.rb +146 -0
  27. data/lib/oci8/compat.rb +117 -0
  28. data/lib/oci8/connection_pool.rb +179 -0
  29. data/lib/oci8/cursor.rb +605 -0
  30. data/lib/oci8/datetime.rb +605 -0
  31. data/lib/oci8/encoding-init.rb +45 -0
  32. data/lib/oci8/encoding.yml +537 -0
  33. data/lib/oci8/metadata.rb +2148 -0
  34. data/lib/oci8/object.rb +641 -0
  35. data/lib/oci8/oci8.rb +756 -0
  36. data/lib/oci8/ocihandle.rb +591 -0
  37. data/lib/oci8/oracle_version.rb +153 -0
  38. data/lib/oci8/properties.rb +196 -0
  39. data/lib/oci8/version.rb +3 -0
  40. data/lib/oci8.rb +190 -0
  41. data/lib/oci8lib_310.so +0 -0
  42. data/lib/ruby-oci8.rb +1 -0
  43. data/metaconfig +142 -0
  44. data/pre-distclean.rb +7 -0
  45. data/ruby-oci8.gemspec +85 -0
  46. data/setup.rb +1342 -0
  47. data/test/README.md +37 -0
  48. data/test/config.rb +201 -0
  49. data/test/setup_test_object.sql +199 -0
  50. data/test/setup_test_package.sql +59 -0
  51. data/test/test_all.rb +56 -0
  52. data/test/test_appinfo.rb +62 -0
  53. data/test/test_array_dml.rb +332 -0
  54. data/test/test_bind_array.rb +70 -0
  55. data/test/test_bind_boolean.rb +99 -0
  56. data/test/test_bind_integer.rb +47 -0
  57. data/test/test_bind_raw.rb +45 -0
  58. data/test/test_bind_string.rb +105 -0
  59. data/test/test_bind_time.rb +177 -0
  60. data/test/test_break.rb +125 -0
  61. data/test/test_clob.rb +85 -0
  62. data/test/test_connection_pool.rb +124 -0
  63. data/test/test_connstr.rb +220 -0
  64. data/test/test_datetime.rb +585 -0
  65. data/test/test_dbi.rb +365 -0
  66. data/test/test_dbi_clob.rb +53 -0
  67. data/test/test_encoding.rb +103 -0
  68. data/test/test_error.rb +87 -0
  69. data/test/test_metadata.rb +2674 -0
  70. data/test/test_object.rb +546 -0
  71. data/test/test_oci8.rb +624 -0
  72. data/test/test_oracle_version.rb +68 -0
  73. data/test/test_oradate.rb +255 -0
  74. data/test/test_oranumber.rb +792 -0
  75. data/test/test_package_type.rb +981 -0
  76. data/test/test_properties.rb +17 -0
  77. data/test/test_rowid.rb +32 -0
  78. metadata +123 -0
data/test/test_dbi.rb ADDED
@@ -0,0 +1,365 @@
1
+ require 'dbi'
2
+ require 'oci8'
3
+ require File.dirname(__FILE__) + '/config'
4
+
5
+ class TestDBI < Minitest::Test
6
+
7
+ def setup
8
+ @dbh = get_dbi_connection()
9
+ end
10
+
11
+ def teardown
12
+ @dbh.disconnect
13
+ end
14
+
15
+ def test_select
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
+ STORAGE (
24
+ INITIAL 4k
25
+ NEXT 4k
26
+ MINEXTENTS 1
27
+ MAXEXTENTS UNLIMITED
28
+ PCTINCREASE 0)
29
+ EOS
30
+ @dbh.do(sql)
31
+ sth = @dbh.prepare("INSERT INTO test_table VALUES (?, ?, ?, ?)")
32
+ 1.upto(10) do |i|
33
+ sth.execute(format("%10d", i * 10), i.to_s, i, nil)
34
+ end
35
+ sth = @dbh.execute("SELECT * FROM test_table ORDER BY c")
36
+ assert_equal(["C", "V", "N", "D"], sth.column_names)
37
+ 1.upto(10) do |i|
38
+ rv = sth.fetch
39
+ assert_equal(format("%10d", i * 10), rv[0])
40
+ assert_equal(i.to_s, rv[1])
41
+ assert_equal(i, rv[2])
42
+ end
43
+ assert_nil(sth.fetch)
44
+ assert_equal(10, @dbh.select_one("SELECT COUNT(*) FROM test_table")[0])
45
+ @dbh.rollback()
46
+ assert_equal(0, @dbh.select_one("SELECT COUNT(*) FROM test_table")[0])
47
+ drop_table('test_table')
48
+ end
49
+
50
+ def test_ref_cursor
51
+ drop_table('test_table')
52
+ sql = <<-EOS
53
+ CREATE TABLE test_table
54
+ (C CHAR(10) NOT NULL,
55
+ V VARCHAR2(20),
56
+ N NUMBER(10, 2),
57
+ D DATE)
58
+ STORAGE (
59
+ INITIAL 4k
60
+ NEXT 4k
61
+ MINEXTENTS 1
62
+ MAXEXTENTS UNLIMITED
63
+ PCTINCREASE 0)
64
+ EOS
65
+ @dbh.do(sql)
66
+ sth = @dbh.prepare("INSERT INTO test_table VALUES (?, ?, ?, ?)")
67
+ 1.upto(10) do |i|
68
+ sth.execute(format("%10d", i * 10), i.to_s, i, nil)
69
+ end
70
+ # get a ref cursor
71
+ plsql = @dbh.execute("BEGIN OPEN ? FOR SELECT * FROM test_table ORDER BY c; END;", DBI::StatementHandle)
72
+ sth = plsql.func(:bind_value, 1)
73
+ assert_equal(["C", "V", "N", "D"], sth.column_names)
74
+ 1.upto(10) do |i|
75
+ rv = sth.fetch
76
+ assert_equal(format("%10d", i * 10), rv[0])
77
+ assert_equal(i.to_s, rv[1])
78
+ assert_equal(i, rv[2])
79
+ end
80
+ @dbh.rollback()
81
+ drop_table('test_table')
82
+ end
83
+
84
+ def test_define
85
+ drop_table('test_table')
86
+ sql = <<-EOS
87
+ CREATE TABLE test_table
88
+ (C CHAR(10) NOT NULL,
89
+ V VARCHAR2(20),
90
+ N NUMBER(10, 2),
91
+ D1 DATE, D2 DATE, D3 DATE, D4 DATE,
92
+ INT NUMBER(30), BIGNUM NUMBER(30))
93
+ STORAGE (
94
+ INITIAL 4k
95
+ NEXT 4k
96
+ MINEXTENTS 1
97
+ MAXEXTENTS UNLIMITED
98
+ PCTINCREASE 0)
99
+ EOS
100
+ @dbh.do(sql)
101
+ sth = @dbh.prepare("INSERT INTO test_table VALUES (:C, :V, :N, :D1, :D2, :D3, :D4, :INT, :BIGNUM)")
102
+ 1.upto(10) do |i|
103
+ if i == 1
104
+ if OCI8::oracle_client_version >= OCI8::ORAVER_9_0
105
+ dt = nil
106
+ v = ''
107
+ sth.execute(format("%10d", i * 10), v, i, dt, dt, dt, dt, i, i)
108
+ else
109
+ # explicitly bind nil with datatype to avoid ORA-01475 when using Oracle 8i.
110
+ sth.bind_param(1, format("%10d", i * 10))
111
+ sth.bind_param(2, '')
112
+ sth.bind_param(3, i)
113
+ sth.bind_param(4, nil, {'type' => OraDate})
114
+ sth.bind_param(5, nil, {'type' => OraDate})
115
+ sth.bind_param(6, nil, {'type' => OraDate})
116
+ sth.bind_param(7, nil, {'type' => OraDate})
117
+ sth.bind_param(8, i)
118
+ sth.bind_param(9, i)
119
+ sth.execute
120
+ end
121
+ else
122
+ dt = OraDate.new(2000 + i, 8, 3, 23, 59, 59)
123
+ v = i.to_s
124
+ sth.execute(format("%10d", i * 10), v, i, dt, dt, dt, dt, i, i)
125
+ end
126
+ end
127
+ sth.finish
128
+ sth = @dbh.prepare("SELECT * FROM test_table ORDER BY c")
129
+ sth.func(:define, 5, Time) # define 5th column as Time
130
+ sth.func(:define, 6, Date) # define 6th column as Date
131
+ sth.func(:define, 7, DateTime) # define 7th column as DateTime
132
+ sth.func(:define, 8, Integer) # define 8th column as Integer
133
+ sth.func(:define, 9, Bignum) # define 9th column as Bignum
134
+ sth.execute
135
+ assert_equal(["C", "V", "N", "D1", "D2", "D3", "D4", "INT", "BIGNUM"], sth.column_info.collect {|cl| cl.name})
136
+ 1.upto(10) do |i|
137
+ rv = sth.fetch
138
+ assert_equal(format("%10d", i * 10), rv[0])
139
+ assert_equal(i, rv[2])
140
+ if i == 1
141
+ assert_nil(rv[1])
142
+ assert_nil(rv[3])
143
+ assert_nil(rv[4])
144
+ assert_nil(rv[5])
145
+ assert_nil(rv[6])
146
+ else
147
+ assert_equal(i.to_s, rv[1])
148
+ tm = Time.local(2000 + i, 8, 3, 23, 59, 59)
149
+ dt = Date.civil(2000 + i, 8, 3)
150
+ dttm = DateTime.civil(2000 + i, 8, 3, 23, 59, 59, Time.now.utc_offset.to_r/86400)
151
+ assert_equal(tm, rv[3])
152
+ assert_equal(tm, rv[4])
153
+ assert_equal(dt, rv[5])
154
+ assert_equal(dttm, rv[6])
155
+ assert_instance_of(Time, rv[4])
156
+ assert_instance_of(Date, rv[5])
157
+ assert_instance_of(DateTime, rv[6])
158
+ end
159
+ assert_equal(i, rv[7])
160
+ assert_equal(i, rv[8])
161
+ end
162
+ assert_nil(sth.fetch)
163
+ sth.finish
164
+ drop_table('test_table')
165
+ end
166
+
167
+ def test_bind_dbi_data_type
168
+ begin
169
+ if DBI::VERSION >= '0.4.0'
170
+ # suppress deprecated warnings while running this test.
171
+ saved_action = Deprecated.action
172
+ Deprecated.set_action(Proc.new {})
173
+ end
174
+
175
+ inval = DBI::Date.new(2004, 3, 20)
176
+ sth = @dbh.execute("BEGIN ? := ?; END;", DBI::Date, inval)
177
+ outval = sth.func(:bind_value, 1)
178
+ assert_instance_of(DBI::Date, outval)
179
+ assert_equal(inval.to_time, outval.to_time)
180
+
181
+ inval = DBI::Timestamp.new(2004, 3, 20, 18, 26, 33)
182
+ sth = @dbh.execute("BEGIN ? := ?; END;", DBI::Timestamp, inval)
183
+ outval = sth.func(:bind_value, 1)
184
+ assert_instance_of(DBI::Timestamp, outval)
185
+ assert_equal(inval.to_time, outval.to_time)
186
+ ensure
187
+ Deprecated.set_action(saved_action) if saved_action
188
+ end
189
+ end
190
+
191
+ def test_column_info
192
+ if $oracle_version < OCI8::ORAVER_8_1
193
+ begin
194
+ @dbh.columns('tab')
195
+ rescue RuntimeError
196
+ assert_equal("This feature is unavailable on Oracle 8.0", $!.to_s)
197
+ end
198
+ return
199
+ end
200
+
201
+ # data_size factor for nchar charset_form.
202
+ sth = @dbh.execute("select N'1' from dual")
203
+ cfrm = sth.column_info[0]['precision']
204
+ if $oracle_version >= OCI8::ORAVER_9_0
205
+ # data_size factor for char semantics.
206
+ sth = @dbh.execute("select CAST('1' AS CHAR(1 char)) from dual")
207
+ csem = sth.column_info[0]['precision']
208
+ else
209
+ csem = 1
210
+ end
211
+
212
+ ora80 = OCI8::ORAVER_8_0
213
+ ora81 = OCI8::ORAVER_8_1
214
+ ora90 = OCI8::ORAVER_9_0
215
+ ora101 = OCI8::ORAVER_10_1
216
+ coldef =
217
+ [
218
+ # oracle_version, definition, sql_type, type_name, nullable, precision,scale,indexed,primary,unique,default
219
+ [ora80, "CHAR(10) NOT NULL", DBI::SQL_CHAR, 'CHAR', false, 10, nil, true, true, true, nil],
220
+ [ora90, "CHAR(10 CHAR)", DBI::SQL_CHAR, 'CHAR', true, 10 * csem, nil, false,false,false,nil],
221
+ [ora80, "NCHAR(10)", DBI::SQL_CHAR, 'NCHAR', true, 10 * cfrm, nil, true, false,true, nil],
222
+ [ora80, "VARCHAR2(10) DEFAULT 'a''b'", DBI::SQL_VARCHAR, 'VARCHAR2', true, 10, nil, true, false,false, "a'b"],
223
+ [ora90, "VARCHAR2(10 CHAR)", DBI::SQL_VARCHAR, 'VARCHAR2', true, 10 * csem, nil, false,false,false,nil],
224
+ [ora80, "NVARCHAR2(10)", DBI::SQL_VARCHAR, 'NVARCHAR2',true, 10 * cfrm, nil, false,false,false,nil],
225
+ [ora80, "RAW(10)", DBI::SQL_VARBINARY, 'RAW', true, 10, nil, false,false,false,nil],
226
+ [ora81, "CLOB", DBI::SQL_CLOB, 'CLOB', true, 4000, nil, false,false,false,nil],
227
+ [ora81, "NCLOB", DBI::SQL_CLOB, 'NCLOB', true, 4000, nil, false,false,false,nil],
228
+ [ora80, "BLOB", DBI::SQL_BLOB, 'BLOB', true, 4000, nil, false,false,false,nil],
229
+ [ora80, "BFILE", DBI::SQL_BLOB, 'BFILE', true, 4000, nil, false,false,false,nil],
230
+ [ora80, "NUMBER", DBI::SQL_NUMERIC, 'NUMBER', true, 38, nil, false,false,false,nil],
231
+ [ora80, "NUMBER(10)", DBI::SQL_NUMERIC, 'NUMBER', true, 10, 0, false,false,false,nil],
232
+ [ora80, "NUMBER(10,2)", DBI::SQL_NUMERIC, 'NUMBER', true, 10, 2, false,false,false,nil],
233
+ [ora80, "FLOAT", DBI::SQL_FLOAT, 'FLOAT', true, (126 * 0.30103).ceil, nil, false,false,false,nil],
234
+ [ora80, "FLOAT(10)", DBI::SQL_FLOAT, 'FLOAT', true, (10 * 0.30103).ceil, nil, false,false,false,nil],
235
+ [ora101,"BINARY_FLOAT", DBI::SQL_FLOAT, 'BINARY_FLOAT', true, 7, nil, false,false,false,nil],
236
+ [ora101,"BINARY_DOUBLE", DBI::SQL_DOUBLE, 'BINARY_DOUBLE', true, 16, nil, false,false,false,nil],
237
+ [ora80, "DATE", DBI::SQL_DATE, 'DATE', true, 19, nil, false,false,false,nil],
238
+ [ora90, "TIMESTAMP", DBI::SQL_TIMESTAMP, 'TIMESTAMP', true, 20 + 6, nil, false,false,false,nil],
239
+ [ora90, "TIMESTAMP(9)", DBI::SQL_TIMESTAMP, 'TIMESTAMP', true, 20 + 9, nil, false,false,false,nil],
240
+ [ora90, "TIMESTAMP WITH TIME ZONE", DBI::SQL_TIMESTAMP, 'TIMESTAMP WITH TIME ZONE', true, 27 + 6, nil, false,false,false,nil],
241
+ [ora90, "TIMESTAMP(9) WITH TIME ZONE", DBI::SQL_TIMESTAMP, 'TIMESTAMP WITH TIME ZONE', true, 27 + 9, nil, false,false,false,nil],
242
+ [ora90, "TIMESTAMP WITH LOCAL TIME ZONE", DBI::SQL_TIMESTAMP, 'TIMESTAMP WITH LOCAL TIME ZONE', true, 20 + 6, nil, false,false,false,nil],
243
+ [ora90, "TIMESTAMP(9) WITH LOCAL TIME ZONE", DBI::SQL_TIMESTAMP, 'TIMESTAMP WITH LOCAL TIME ZONE', true, 20 + 9, nil, false,false,false,nil],
244
+ [ora90, "INTERVAL YEAR TO MONTH", DBI::SQL_OTHER, 'INTERVAL YEAR TO MONTH', true, 2 + 3, nil, false,false,false,nil],
245
+ [ora90, "INTERVAL YEAR(4) TO MONTH", DBI::SQL_OTHER, 'INTERVAL YEAR TO MONTH', true, 4 + 3, nil, false,false,false,nil],
246
+ [ora90, "INTERVAL DAY TO SECOND", DBI::SQL_OTHER, 'INTERVAL DAY TO SECOND', true, 2 + 10 + 6, nil, false,false,false,nil],
247
+ [ora90, "INTERVAL DAY(4) TO SECOND(9)",DBI::SQL_OTHER, 'INTERVAL DAY TO SECOND', true, 4 + 10 + 9, nil, false,false,false,nil],
248
+ ]
249
+
250
+ coldef.reject! do |c| c[0] > $oracle_version end
251
+
252
+ drop_table('test_table')
253
+ @dbh.execute(<<-EOS)
254
+ CREATE TABLE test_table (#{n = 0; coldef.collect do |c| n += 1; "C#{n} " + c[1] + (c[8] ? ' PRIMARY KEY' : ''); end.join(',')})
255
+ STORAGE (
256
+ INITIAL 100k
257
+ NEXT 100k
258
+ MINEXTENTS 1
259
+ MAXEXTENTS UNLIMITED
260
+ PCTINCREASE 0)
261
+ EOS
262
+ coldef.each_with_index do |col, idx|
263
+ next if col[8] # primary
264
+ if col[7] # indexed
265
+ @dbh.execute(<<-EOS)
266
+ CREATE #{col[9] ? 'UNIQUE' : ''} INDEX test_table_idx#{idx + 1} ON test_table(C#{idx + 1})
267
+ STORAGE (
268
+ INITIAL 100k
269
+ NEXT 100k
270
+ MINEXTENTS 1
271
+ MAXEXTENTS UNLIMITED
272
+ PCTINCREASE 0)
273
+ EOS
274
+ end
275
+ end
276
+
277
+ @dbh.columns('test_table').each_with_index do |ci, i|
278
+ assert_equal("C#{i + 1}", ci['name'], "'#{coldef[i][1]}': name")
279
+ assert_equal(coldef[i][2], ci['sql_type'], "'#{coldef[i][1]}': sql_type")
280
+ assert_equal(coldef[i][3], ci['type_name'], "'#{coldef[i][1]}': type_name")
281
+ assert_equal(coldef[i][4], ci['nullable'], "'#{coldef[i][1]}': nullable")
282
+ assert_equal(coldef[i][5], ci['precision'], "'#{coldef[i][1]}': precision")
283
+ assert_equal(coldef[i][6], ci['scale'], "'#{coldef[i][1]}': scale")
284
+ assert_equal(coldef[i][7], ci['indexed'], "'#{coldef[i][1]}': indexed")
285
+ assert_equal(coldef[i][8], ci['primary'], "'#{coldef[i][1]}': primary")
286
+ assert_equal(coldef[i][9], ci['unique'], "'#{coldef[i][1]}': unique")
287
+ assert_equal(coldef[i][10],ci['default'], "'#{coldef[i][1]}': default")
288
+ end
289
+
290
+ # temporarily change OCI8::BindType::Mapping.
291
+ saved_mapping = {}
292
+ [OCI8::SQLT_TIMESTAMP_TZ,
293
+ OCI8::SQLT_TIMESTAMP_LTZ,
294
+ OCI8::SQLT_INTERVAL_YM,
295
+ OCI8::SQLT_INTERVAL_DS].each do |sqlt_type|
296
+ saved_mapping[sqlt_type] = OCI8::BindType::Mapping[sqlt_type]
297
+ OCI8::BindType::Mapping[sqlt_type] = OCI8::BindType::String
298
+ end
299
+ begin
300
+ sth = @dbh.execute("SELECT * FROM test_table")
301
+ ensure
302
+ saved_mapping.each do |key, val|
303
+ OCI8::BindType::Mapping[key] = val
304
+ end
305
+ end
306
+ sth.column_info.each_with_index do |ci, i|
307
+ assert_equal("C#{i + 1}", ci['name'], "'#{coldef[i][1]}': name")
308
+ assert_equal(coldef[i][2], ci['sql_type'], "'#{coldef[i][1]}': sql_type")
309
+ assert_equal(coldef[i][3], ci['type_name'], "'#{coldef[i][1]}': type_name")
310
+ assert_equal(coldef[i][4], ci['nullable'], "'#{coldef[i][1]}': nullable")
311
+ assert_equal(coldef[i][5], ci['precision'], "'#{coldef[i][1]}': precision")
312
+ assert_equal(coldef[i][6], ci['scale'], "'#{coldef[i][1]}': scale")
313
+ assert_equal(nil, ci['indexed'], "'#{coldef[i][1]}': indexed")
314
+ assert_equal(nil, ci['primary'], "'#{coldef[i][1]}': primary")
315
+ assert_equal(nil, ci['unique'], "'#{coldef[i][1]}': unique")
316
+ assert_equal(nil, ci['default'], "'#{coldef[i][1]}': default")
317
+ end
318
+
319
+ drop_table('test_table')
320
+ end
321
+
322
+ def test_column_info_of_tab
323
+ coldef =
324
+ [
325
+ # name, sql_type, type_name, nullable,precision,scale,indexed,primary,unique,default
326
+ ["TNAME", DBI::SQL_VARCHAR,'VARCHAR2',false, 30, nil, false, false, false, nil],
327
+ ["TABTYPE", DBI::SQL_VARCHAR,'VARCHAR2',true, 7, nil, false, false, false, nil],
328
+ ["CLUSTERID",DBI::SQL_NUMERIC,'NUMBER', true, 38, nil, false, false, false, nil],
329
+ ]
330
+ begin
331
+ @dbh.columns('tab').each_with_index do |ci, i|
332
+ assert_equal(coldef[i][0], ci['name'], "'#{coldef[i][0]}': name")
333
+ assert_equal(coldef[i][1], ci['sql_type'], "'#{coldef[i][0]}': sql_type")
334
+ assert_equal(coldef[i][2], ci['type_name'], "'#{coldef[i][0]}': type_name")
335
+ assert_equal(coldef[i][3], ci['nullable'], "'#{coldef[i][0]}': nullable")
336
+ assert_equal(coldef[i][4], ci['precision'], "'#{coldef[i][0]}': precision")
337
+ assert_equal(coldef[i][5], ci['scale'], "'#{coldef[i][0]}': scale")
338
+ assert_equal(coldef[i][6], ci['indexed'], "'#{coldef[i][0]}': indexed")
339
+ assert_equal(coldef[i][7], ci['primary'], "'#{coldef[i][0]}': primary")
340
+ assert_equal(coldef[i][8], ci['unique'], "'#{coldef[i][0]}': unique")
341
+ assert_equal(coldef[i][9], ci['default'], "'#{coldef[i][0]}': default")
342
+ end
343
+ rescue RuntimeError
344
+ if $oracle_version < OCI8::ORAVER_8_1
345
+ assert_equal("This feature is unavailable on Oracle 8.0", $!.to_s)
346
+ else
347
+ raise
348
+ end
349
+ end
350
+
351
+ @dbh.execute("SELECT * FROM tab").column_info.each_with_index do |ci, i|
352
+ assert_equal(coldef[i][0], ci['name'], "'#{coldef[i][0]}': name")
353
+ assert_equal(coldef[i][1], ci['sql_type'], "'#{coldef[i][0]}': sql_type")
354
+ assert_equal(coldef[i][2], ci['type_name'], "'#{coldef[i][0]}': type_name")
355
+ assert_equal(coldef[i][3], ci['nullable'], "'#{coldef[i][0]}': nullable")
356
+ assert_equal(coldef[i][4], ci['precision'], "'#{coldef[i][0]}': precision")
357
+ assert_equal(coldef[i][5], ci['scale'], "'#{coldef[i][0]}': scale")
358
+ assert_equal(nil, ci['indexed'], "'#{coldef[i][0]}': indexed")
359
+ assert_equal(nil, ci['primary'], "'#{coldef[i][0]}': primary")
360
+ assert_equal(nil, ci['unique'], "'#{coldef[i][0]}': unique")
361
+ assert_equal(nil, ci['default'], "'#{coldef[i][0]}': default")
362
+ end
363
+ end
364
+
365
+ end # TestDBI
@@ -0,0 +1,53 @@
1
+ require 'dbi'
2
+ require 'oci8'
3
+ require File.dirname(__FILE__) + '/config'
4
+
5
+ class TestDbiCLob < Minitest::Test
6
+
7
+ def setup
8
+ @dbh = get_dbi_connection()
9
+ drop_table('test_table')
10
+ @dbh.execute('CREATE TABLE test_table (filename VARCHAR2(40), content CLOB)')
11
+ end
12
+
13
+ def test_insert
14
+ filename = File.basename($lobfile)
15
+
16
+ # insert an empty clob and get the rowid.
17
+ rowid = @dbh.execute("INSERT INTO test_table(filename, content) VALUES (:1, EMPTY_CLOB())", filename) do |sth|
18
+ sth.func(:rowid)
19
+ end
20
+ lob = @dbh.select_one("SELECT content FROM test_table WHERE filename = :1 FOR UPDATE", filename)[0]
21
+ begin
22
+ open($lobfile) do |f|
23
+ while f.gets()
24
+ lob.write($_)
25
+ end
26
+ end
27
+ ensure
28
+ lob.close()
29
+ end
30
+ end
31
+
32
+ def test_read
33
+ filename = File.basename($lobfile)
34
+ test_insert() # first insert data.
35
+ lob = @dbh.select_one("SELECT content FROM test_table WHERE filename = :1 FOR UPDATE", filename)[0]
36
+ begin
37
+ open($lobfile) do |f|
38
+ while buf = lob.read($lobreadnum)
39
+ fbuf = f.read(buf.size)
40
+ assert_equal(fbuf, buf)
41
+ end
42
+ assert_equal(nil, buf)
43
+ assert_equal(true, f.eof?)
44
+ end
45
+ ensure
46
+ lob.close()
47
+ end
48
+ end
49
+
50
+ def teardown
51
+ @dbh.disconnect
52
+ end
53
+ end
@@ -0,0 +1,103 @@
1
+ require 'oci8'
2
+ require File.dirname(__FILE__) + '/config'
3
+
4
+ class TestEncoding < Minitest::Test
5
+ def setup
6
+ @conn = get_oci8_connection
7
+ end
8
+
9
+ def test_select
10
+ drop_table('test_table')
11
+ @conn.exec(<<EOS)
12
+ CREATE TABLE test_table
13
+ (C CHAR(10),
14
+ V VARCHAR2(10),
15
+ R RAW(10),
16
+ LR LONG RAW,
17
+ CL CLOB,
18
+ NCL NCLOB,
19
+ BL BLOB)
20
+ STORAGE (
21
+ INITIAL 4k
22
+ NEXT 4k
23
+ MINEXTENTS 1
24
+ MAXEXTENTS UNLIMITED
25
+ PCTINCREASE 0)
26
+ EOS
27
+ ascii_8bit = "\xab\xcd".force_encoding('ASCII-8BIT')
28
+ @conn.exec(<<EOS)
29
+ INSERT INTO test_table VALUES ('abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd')
30
+ EOS
31
+ @conn.exec("SELECT * FROM test_table") do |row|
32
+ assert_equal('abcd ', row[0], 'CHAR(10)')
33
+ assert_equal(OCI8.encoding, row[0].encoding);
34
+ assert_equal('abcd', row[1], 'VARCHAR2(10)')
35
+ assert_equal(OCI8.encoding, row[1].encoding);
36
+ assert_equal(ascii_8bit, row[2], 'RAW(10)')
37
+ assert_equal(ascii_8bit.encoding, row[2].encoding);
38
+ assert_equal(ascii_8bit, row[3], 'LONG RAW')
39
+ assert_equal(ascii_8bit.encoding, row[3].encoding);
40
+ assert_equal('abcd', (data = row[4].read), 'CLOB')
41
+ assert_equal(OCI8.encoding, data.encoding);
42
+ assert_equal('abcd', (data = row[5].read), 'NCLOB')
43
+ assert_equal(OCI8.encoding, data.encoding);
44
+ assert_equal(ascii_8bit, (data = row[6].read), 'BLOB')
45
+ assert_equal(ascii_8bit.encoding, data.encoding);
46
+
47
+ if OCI8.encoding.name == "UTF-8" and ['WE8ISO8859P1', 'WE8ISO8859P15', 'AL32UTF8', 'UTF8'].include? @conn.database_charset_name
48
+ utf_8 = "\u00A1\u00A2\u00A3\u00A5\u00A7\u00A9"
49
+ iso_8859_1 = utf_8.encode("ISO-8859-15")
50
+ # CLOB
51
+ lob = row[4]
52
+ lob.rewind
53
+ lob.write(iso_8859_1) # converted to OCI8.encoding(UTF-8)
54
+ lob.rewind
55
+ assert_equal(utf_8, lob.read)
56
+ # NCLOB
57
+ lob = row[5]
58
+ lob.rewind
59
+ lob.write(iso_8859_1) # converted to OCI8.encoding(UTF-8)
60
+ lob.rewind
61
+ assert_equal(utf_8, lob.read)
62
+ # BLOB
63
+ lob = row[6]
64
+ lob.rewind
65
+ lob.write(iso_8859_1) # written without encoding conversion
66
+ lob.rewind
67
+ assert_equal(iso_8859_1.force_encoding('ASCII-8BIT'), lob.read)
68
+ else
69
+ warn "Skip some asserts because the database character set is neither WE8ISO8859P1, WE8ISO8859P15, AL32UTF8 nor UTF8." if OCI8.encoding.name == "UTF-8"
70
+ end
71
+ end
72
+ drop_table('test_table')
73
+ end
74
+
75
+ warn "Skip some tests which runs only when NLS_CHARACTERSETS is unicode." if OCI8.encoding.name != "UTF-8"
76
+
77
+ if OCI8.encoding.name == "UTF-8"
78
+ def test_bind_string_with_code_conversion
79
+ drop_table('test_table')
80
+ @conn.exec(<<EOS)
81
+ CREATE TABLE test_table
82
+ (V VARCHAR2(3000))
83
+ STORAGE (
84
+ INITIAL 4k
85
+ NEXT 4k
86
+ MINEXTENTS 1
87
+ MAXEXTENTS UNLIMITED
88
+ PCTINCREASE 0)
89
+ EOS
90
+ utf_8 = "\u00A1" * 1500 # 3000 byte
91
+ iso_8859_1 = utf_8.encode("ISO-8859-1") # 1500 byte
92
+ @conn.exec("INSERT INTO test_table VALUES (:1)", iso_8859_1)
93
+ @conn.exec("SELECT * FROM test_table") do |row|
94
+ assert_equal(utf_8, row[0])
95
+ end
96
+ drop_table('test_table')
97
+ end
98
+ end
99
+
100
+ def teardown
101
+ @conn.logoff
102
+ end
103
+ end
@@ -0,0 +1,87 @@
1
+ require 'oci8'
2
+ require File.dirname(__FILE__) + '/config'
3
+
4
+ class TestError < Minitest::Test
5
+ def setup
6
+ @conn = get_oci8_connection
7
+ end
8
+
9
+ def teardown
10
+ @conn.logoff
11
+ end
12
+
13
+ def test_sql_parse_error
14
+ sql = 'select * from'
15
+ begin
16
+ @conn.exec(sql) # raises "ORA-00903: invalid table name"
17
+ rescue OCIException
18
+ assert_instance_of(OCIError, $!)
19
+ assert_match(/^ORA-00903: /, $!.to_s)
20
+ assert_equal(903, $!.code)
21
+ assert_equal(13, $!.parse_error_offset)
22
+ assert_equal(13, $!.parseErrorOffset) # barkward compatibility
23
+ assert_equal(sql, $!.sql)
24
+ end
25
+ end
26
+
27
+ def test_plsql_parse_error
28
+ sql = <<EOS
29
+ BEGIN
30
+ SELECT dummy INTO l_dummy FROM dual WHERE 1=2;
31
+ END;
32
+ EOS
33
+ begin
34
+ @conn.exec(sql) # raises "ORA-06550: line 2, column 21"
35
+ rescue OCIException
36
+ assert_instance_of(OCIError, $!)
37
+ assert_match(/^ORA-06550: /, $!.to_s)
38
+ assert_equal(6550, $!.code)
39
+ assert_equal(26, $!.parse_error_offset)
40
+ assert_equal(26, $!.parseErrorOffset) # barkward compatibility
41
+ assert_equal(sql, $!.sql)
42
+ end
43
+ end
44
+
45
+ def test_plsql_error_in_execution
46
+ sql = <<EOS
47
+ DECLARE
48
+ l_dummy VARCHAR2(50);
49
+ BEGIN
50
+ SELECT * INTO l_dummy
51
+ FROM (SELECT DUMMY FROM DUAL
52
+ UNION ALL
53
+ SELECT DUMMY FROM DUAL);
54
+ END;
55
+ EOS
56
+ begin
57
+ @conn.exec(sql) # raises "ORA-01422: exact fetch returns more than requested number of rows"
58
+ rescue OCIException
59
+ assert_instance_of(OCIError, $!)
60
+ assert_match(/^ORA-01422: /, $!.to_s)
61
+ assert_equal(1422, $!.code)
62
+ assert_equal(0, $!.parse_error_offset)
63
+ assert_equal(0, $!.parseErrorOffset) # barkward compatibility
64
+ assert_equal(sql, $!.sql)
65
+ end
66
+ end
67
+
68
+ def test_nodata
69
+ sql = <<EOS
70
+ DECLARE
71
+ l_dummy VARCHAR2(50);
72
+ BEGIN
73
+ SELECT dummy INTO l_dummy FROM dual WHERE 1=2;
74
+ END;
75
+ EOS
76
+ begin
77
+ @conn.exec(sql) # raises "ORA-01403: no data found"
78
+ rescue OCIException
79
+ assert_instance_of(OCINoData, $!)
80
+ assert_match(/^ORA-01403: /, $!.to_s)
81
+ assert_equal(1403, $!.code)
82
+ assert_equal(0, $!.parse_error_offset)
83
+ assert_equal(0, $!.parseErrorOffset) # barkward compatibility
84
+ assert_equal(sql, $!.sql)
85
+ end
86
+ end
87
+ end