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
@@ -0,0 +1,2674 @@
1
+ require 'oci8'
2
+ require File.dirname(__FILE__) + '/config'
3
+
4
+ class TestMetadata < Minitest::Test
5
+
6
+ def setup
7
+ @conn = get_oci8_connection
8
+ end
9
+
10
+ def teardown
11
+ @conn.logoff if @conn
12
+ end
13
+
14
+ def drop_type(name, drop_body = false)
15
+ if drop_body
16
+ begin
17
+ @conn.exec("DROP TYPE BODY #{name}")
18
+ rescue OCIError
19
+ raise if $!.code != 4043
20
+ end
21
+ end
22
+ begin
23
+ @conn.exec("DROP TYPE #{name}")
24
+ rescue OCIError
25
+ raise if $!.code != 4043
26
+ end
27
+ end
28
+
29
+ def to_obj_id(owner_name, object_name)
30
+ @conn.select_one('select object_id from all_objects where owner = :1 and object_name = :2', owner_name, object_name)[0].to_i
31
+ end
32
+
33
+ def check_attributes(msg, obj, attrs)
34
+ attrs.each do |method, expected_value|
35
+ next if expected_value == :skip
36
+
37
+ val = method.is_a?(Array) ? obj[method[0]] : obj.send(method)
38
+ case expected_value
39
+ when Hash
40
+ check_attributes("#{msg} > #{method}", val, expected_value)
41
+ when Proc
42
+ assert(expected_value.call(val), "#{msg} > #{method}")
43
+ when Regexp
44
+ assert_match(expected_value, val, "#{msg} > #{method}")
45
+ when nil
46
+ assert_nil(val, "#{msg} > #{method}")
47
+ else
48
+ assert_equal(expected_value, val, "#{msg} > #{method}")
49
+ end
50
+ end
51
+ end
52
+
53
+ def test_error_describe_table
54
+ drop_table('test_table')
55
+ begin
56
+ @conn.describe_table('test_table')
57
+ flunk("expects ORA-4043 but no error")
58
+ rescue OCIError
59
+ flunk("expects ORA-4043 but ORA-#{$!.code}") if $!.code != 4043
60
+ end
61
+ @conn.exec('create sequence test_table')
62
+ begin
63
+ begin
64
+ @conn.describe_table('test_table')
65
+ flunk('expects ORA-4043 but no error')
66
+ rescue OCIError
67
+ flunk("expects ORA-4043 but ORA-#{$!.code}") if $!.code != 4043
68
+ end
69
+ ensure
70
+ @conn.exec('drop sequence test_table')
71
+ end
72
+ end
73
+
74
+ def test_table_metadata
75
+ drop_table('test_table')
76
+
77
+ # Relational table
78
+ @conn.exec(<<-EOS)
79
+ CREATE TABLE test_table (col1 number(38,0), col2 varchar2(60))
80
+ STORAGE (
81
+ INITIAL 100k
82
+ NEXT 100k
83
+ MINEXTENTS 1
84
+ MAXEXTENTS UNLIMITED
85
+ PCTINCREASE 0)
86
+ EOS
87
+ attrs = {
88
+ :class => OCI8::Metadata::Table,
89
+ :obj_id => to_obj_id(@conn.username, 'TEST_TABLE'),
90
+ :obj_name => 'TEST_TABLE',
91
+ :obj_schema => @conn.username,
92
+ :num_cols => 2,
93
+ :type_metadata => nil,
94
+ :is_temporary? => false,
95
+ :is_typed? => false,
96
+ :duration => nil,
97
+ #:dba => 0,
98
+ #:tablespace => 0,
99
+ :clustered? => false,
100
+ :partitioned? => false,
101
+ :index_only? => false,
102
+ :columns => {
103
+ :class => Array,
104
+ :size => 2,
105
+ [0] => {
106
+ :class => OCI8::Metadata::Column,
107
+ :obj_id => nil,
108
+ :obj_name => nil,
109
+ :obj_schema => nil,
110
+ :name => 'COL1',
111
+ },
112
+ [1] => {
113
+ :class => OCI8::Metadata::Column,
114
+ :obj_id => nil,
115
+ :obj_name => nil,
116
+ :obj_schema => nil,
117
+ :name => 'COL2',
118
+ },
119
+ },
120
+ :inspect => /#<OCI8::Metadata::Table:\(\d+\) #{@conn.username}.TEST_TABLE>/,
121
+ }
122
+ [
123
+ @conn.describe_any('test_table'),
124
+ @conn.describe_table('test_table'),
125
+ @conn.describe_schema(@conn.username).objects.detect do |obj|
126
+ obj.obj_name == 'TEST_TABLE'
127
+ end
128
+ ].each do |desc|
129
+ check_attributes("line: #{__LINE__}", desc, attrs)
130
+ end
131
+ drop_table('test_table')
132
+
133
+ # Transaction-specific temporary table
134
+ @conn.exec(<<-EOS)
135
+ CREATE GLOBAL TEMPORARY TABLE test_table (col1 number(38,0), col2 varchar2(60))
136
+ EOS
137
+ attrs = {
138
+ :class => OCI8::Metadata::Table,
139
+ :obj_id => to_obj_id(@conn.username, 'TEST_TABLE'),
140
+ :obj_name => 'TEST_TABLE',
141
+ :obj_schema => @conn.username,
142
+ :num_cols => 2,
143
+ :type_metadata => nil,
144
+ :is_temporary? => true,
145
+ :is_typed? => false,
146
+ :duration => :transaction,
147
+ #:dba => 0,
148
+ #:tablespace => 0,
149
+ :clustered? => false,
150
+ :partitioned? => false,
151
+ :index_only? => false,
152
+ :columns => {
153
+ :class => Array,
154
+ :size => 2,
155
+ [0] => {
156
+ :class => OCI8::Metadata::Column,
157
+ :obj_id => nil,
158
+ :obj_name => nil,
159
+ :obj_schema => nil,
160
+ :name => 'COL1',
161
+ },
162
+ [1] => {
163
+ :class => OCI8::Metadata::Column,
164
+ :obj_id => nil,
165
+ :obj_name => nil,
166
+ :obj_schema => nil,
167
+ :name => 'COL2',
168
+ },
169
+ },
170
+ :inspect => /#<OCI8::Metadata::Table:\(\d+\) #{@conn.username}.TEST_TABLE>/,
171
+ }
172
+ [
173
+ @conn.describe_any('test_table'),
174
+ @conn.describe_table('test_table'),
175
+ @conn.describe_schema(@conn.username).objects.detect do |obj|
176
+ obj.obj_name == 'TEST_TABLE'
177
+ end
178
+ ].each do |desc|
179
+ check_attributes("line: #{__LINE__}", desc, attrs)
180
+ end
181
+ drop_table('test_table')
182
+
183
+ # Session-specific temporary table
184
+ @conn.exec(<<-EOS)
185
+ CREATE GLOBAL TEMPORARY TABLE test_table (col1 number(38,0), col2 varchar2(60))
186
+ ON COMMIT PRESERVE ROWS
187
+ EOS
188
+ attrs = {
189
+ :class => OCI8::Metadata::Table,
190
+ :obj_id => to_obj_id(@conn.username, 'TEST_TABLE'),
191
+ :obj_name => 'TEST_TABLE',
192
+ :obj_schema => @conn.username,
193
+ :num_cols => 2,
194
+ :type_metadata => nil,
195
+ :is_temporary? => true,
196
+ :is_typed? => false,
197
+ :duration => :session,
198
+ #:dba => 0,
199
+ #:tablespace => 0,
200
+ :clustered? => false,
201
+ :partitioned? => false,
202
+ :index_only? => false,
203
+ :columns => {
204
+ :class => Array,
205
+ :size => 2,
206
+ [0] => {
207
+ :class => OCI8::Metadata::Column,
208
+ :obj_id => nil,
209
+ :obj_name => nil,
210
+ :obj_schema => nil,
211
+ :name => 'COL1',
212
+ },
213
+ [1] => {
214
+ :class => OCI8::Metadata::Column,
215
+ :obj_id => nil,
216
+ :obj_name => nil,
217
+ :obj_schema => nil,
218
+ :name => 'COL2',
219
+ },
220
+ },
221
+ :inspect => /#<OCI8::Metadata::Table:\(\d+\) #{@conn.username}.TEST_TABLE>/,
222
+ }
223
+ [
224
+ @conn.describe_any('test_table'),
225
+ @conn.describe_table('test_table'),
226
+ @conn.describe_schema(@conn.username).objects.detect do |obj|
227
+ obj.obj_name == 'TEST_TABLE'
228
+ end
229
+ ].each do |desc|
230
+ check_attributes("line: #{__LINE__}", desc, attrs)
231
+ end
232
+ drop_table('test_table')
233
+
234
+ # Object table
235
+ @conn.exec(<<-EOS)
236
+ CREATE OR REPLACE TYPE test_type AS OBJECT (col1 number(38,0), col2 varchar2(60))
237
+ EOS
238
+ @conn.exec(<<-EOS)
239
+ CREATE TABLE test_table OF test_type
240
+ EOS
241
+ attrs = {
242
+ :class => OCI8::Metadata::Table,
243
+ :obj_id => to_obj_id(@conn.username, 'TEST_TABLE'),
244
+ :obj_name => 'TEST_TABLE',
245
+ :obj_schema => @conn.username,
246
+ :num_cols => 2,
247
+ :type_metadata => {
248
+ :class => OCI8::Metadata::Type,
249
+ :obj_id => 0,
250
+ :obj_name => nil,
251
+ :obj_schema => nil,
252
+ :typecode => :named_type,
253
+ :collection_typecode => nil,
254
+ :is_incomplete_type? => false,
255
+ :is_system_type? => false,
256
+ :is_predefined_type? => false,
257
+ :is_transient_type? => false,
258
+ :is_system_generated_type? => false,
259
+ :has_nested_table? => false,
260
+ :has_lob? => false,
261
+ :has_file? => false,
262
+ :collection_element => nil,
263
+ :num_type_attrs => 2,
264
+ :num_type_methods => 0,
265
+ :map_method => nil,
266
+ :order_method => nil,
267
+ :is_invoker_rights? => false,
268
+ :name => 'TEST_TYPE',
269
+ :schema_name => @conn.username,
270
+ :is_final_type? => true,
271
+ :is_instantiable_type? => true,
272
+ :is_subtype? => false,
273
+ :package_name => nil,
274
+ :type_attrs => {
275
+ :class => Array,
276
+ :size => 2,
277
+ [0] => {
278
+ :class => OCI8::Metadata::TypeAttr,
279
+ :obj_id => nil,
280
+ :obj_name => nil,
281
+ :obj_schema => nil,
282
+ :data_size => 22,
283
+ :typecode => :number,
284
+ :data_type => :number,
285
+ :name => 'COL1',
286
+ :precision => 38,
287
+ :scale => 0,
288
+ :type_name => 'NUMBER',
289
+ :schema_name => 'SYS',
290
+ :fsprecision => 0,
291
+ :lfprecision => 38,
292
+ :type_metadata => {
293
+ :class => OCI8::Metadata::Type,
294
+ },
295
+ :inspect => '#<OCI8::Metadata::TypeAttr: COL1 NUMBER(38)>',
296
+ },
297
+ [1] => {
298
+ :class => OCI8::Metadata::TypeAttr,
299
+ :obj_id => nil,
300
+ :obj_name => nil,
301
+ :obj_schema => nil,
302
+ :data_size => 60,
303
+ :typecode => :varchar2,
304
+ :data_type => :varchar2,
305
+ :name => 'COL2',
306
+ :precision => 0,
307
+ :scale => 0,
308
+ :type_name => 'VARCHAR2',
309
+ :schema_name => 'SYS',
310
+ :fsprecision => 0,
311
+ :lfprecision => 60,
312
+ :type_metadata => {
313
+ :class => OCI8::Metadata::Type,
314
+ },
315
+ :inspect => '#<OCI8::Metadata::TypeAttr: COL2 VARCHAR2(60)>',
316
+ },
317
+ },
318
+ :type_methods => [],
319
+ :inspect => "#<OCI8::Metadata::Type:(0) #{@conn.username}.TEST_TYPE>",
320
+ },
321
+ :is_temporary? => false,
322
+ :is_typed? => true,
323
+ :duration => nil,
324
+ #:dba => 0,
325
+ #:tablespace => 0,
326
+ :clustered? => false,
327
+ :partitioned? => false,
328
+ :index_only? => false,
329
+ :columns => {
330
+ :class => Array,
331
+ :size => 2,
332
+ [0] => {
333
+ :class => OCI8::Metadata::Column,
334
+ :obj_id => nil,
335
+ :obj_name => nil,
336
+ :obj_schema => nil,
337
+ :name => 'COL1',
338
+ },
339
+ [1] => {
340
+ :class => OCI8::Metadata::Column,
341
+ :obj_id => nil,
342
+ :obj_name => nil,
343
+ :obj_schema => nil,
344
+ :name => 'COL2',
345
+ },
346
+ },
347
+ :inspect => /#<OCI8::Metadata::Table:\(\d+\) #{@conn.username}.TEST_TABLE>/,
348
+ }
349
+ [
350
+ @conn.describe_any('test_table'),
351
+ @conn.describe_table('test_table'),
352
+ @conn.describe_schema(@conn.username).objects.detect do |obj|
353
+ obj.obj_name == 'TEST_TABLE'
354
+ end
355
+ ].each do |desc|
356
+ check_attributes("line: #{__LINE__}", desc, attrs)
357
+ end
358
+ drop_table('test_table')
359
+ @conn.exec('DROP TYPE TEST_TYPE')
360
+
361
+ # Index-organized table
362
+ @conn.exec(<<-EOS)
363
+ CREATE TABLE test_table (col1 number(38,0) PRIMARY KEY, col2 varchar2(60))
364
+ ORGANIZATION INDEX
365
+ EOS
366
+ attrs = {
367
+ :class => OCI8::Metadata::Table,
368
+ :obj_id => to_obj_id(@conn.username, 'TEST_TABLE'),
369
+ :obj_name => 'TEST_TABLE',
370
+ :obj_schema => @conn.username,
371
+ :num_cols => 2,
372
+ :type_metadata => nil,
373
+ :is_temporary? => false,
374
+ :is_typed? => false,
375
+ :duration => nil,
376
+ #:dba => 0,
377
+ #:tablespace => 0,
378
+ :clustered? => false,
379
+ :partitioned? => false,
380
+ :index_only? => true,
381
+ :columns => {
382
+ :class => Array,
383
+ :size => 2,
384
+ [0] => {
385
+ :class => OCI8::Metadata::Column,
386
+ :obj_id => nil,
387
+ :obj_name => nil,
388
+ :obj_schema => nil,
389
+ :name => 'COL1',
390
+ },
391
+ [1] => {
392
+ :class => OCI8::Metadata::Column,
393
+ :obj_id => nil,
394
+ :obj_name => nil,
395
+ :obj_schema => nil,
396
+ :name => 'COL2',
397
+ },
398
+ },
399
+ :inspect => /#<OCI8::Metadata::Table:\(\d+\) #{@conn.username}.TEST_TABLE>/,
400
+ }
401
+ [
402
+ @conn.describe_any('test_table'),
403
+ @conn.describe_table('test_table'),
404
+ @conn.describe_schema(@conn.username).objects.detect do |obj|
405
+ obj.obj_name == 'TEST_TABLE'
406
+ end
407
+ ].each do |desc|
408
+ check_attributes("line: #{__LINE__}", desc, attrs)
409
+ end
410
+ drop_table('test_table')
411
+ end # test_table_metadata
412
+
413
+ def test_view_metadata
414
+ @conn.exec('CREATE OR REPLACE VIEW test_view as SELECT * FROM tab')
415
+ attrs = {
416
+ :class => OCI8::Metadata::View,
417
+ :obj_id => to_obj_id(@conn.username, 'TEST_VIEW'),
418
+ :obj_name => 'TEST_VIEW',
419
+ :obj_schema => @conn.username,
420
+ :num_cols => 3,
421
+ :columns => {
422
+ :class => Array,
423
+ :size => 3,
424
+ [0] => {
425
+ :class => OCI8::Metadata::Column,
426
+ :obj_id => nil,
427
+ :obj_name => nil,
428
+ :obj_schema => nil,
429
+ :name => 'TNAME',
430
+ },
431
+ [1] => {
432
+ :class => OCI8::Metadata::Column,
433
+ :obj_id => nil,
434
+ :obj_name => nil,
435
+ :obj_schema => nil,
436
+ :name => 'TABTYPE',
437
+ },
438
+ [2] => {
439
+ :class => OCI8::Metadata::Column,
440
+ :obj_id => nil,
441
+ :obj_name => nil,
442
+ :obj_schema => nil,
443
+ :name => 'CLUSTERID',
444
+ },
445
+ },
446
+ :inspect => /#<OCI8::Metadata::View:\(\d+\) #{@conn.username}.TEST_VIEW>/,
447
+ }
448
+ [
449
+ @conn.describe_any('test_view'),
450
+ @conn.describe_view('test_view'),
451
+ @conn.describe_table('test_view'),
452
+ @conn.describe_schema(@conn.username).objects.detect do |obj|
453
+ obj.obj_name == 'TEST_VIEW'
454
+ end
455
+ ].each do |desc|
456
+ check_attributes("line: #{__LINE__}", desc, attrs)
457
+ end
458
+ @conn.exec('DROP VIEW test_view')
459
+ end # test_view_metadata
460
+
461
+ def test_procedure_metadata
462
+ @conn.exec(<<-EOS)
463
+ CREATE OR REPLACE PROCEDURE test_proc(arg1 IN INTEGER, arg2 OUT varchar2) IS
464
+ BEGIN
465
+ NULL;
466
+ END;
467
+ EOS
468
+ attrs = {
469
+ :class => OCI8::Metadata::Procedure,
470
+ :obj_id => to_obj_id(@conn.username, 'TEST_PROC'),
471
+ :obj_name => 'TEST_PROC',
472
+ :obj_schema => @conn.username,
473
+ :is_invoker_rights? => false,
474
+ :name => 'TEST_PROC',
475
+ :overload_id => nil,
476
+ :arguments => {
477
+ :class => Array,
478
+ :size => 2,
479
+ [0] => {
480
+ :class => OCI8::Metadata::Argument,
481
+ :obj_id => nil,
482
+ :obj_name => nil,
483
+ :obj_schema => nil,
484
+ :name => "ARG1",
485
+ :position => 1,
486
+ #:typecode => nil,
487
+ :data_type => :number,
488
+ :data_size => 22,
489
+ :precision => 38,
490
+ :scale => 0,
491
+ :level => 0,
492
+ :has_default => 0,
493
+ :has_default? => false,
494
+ :iomode => :in,
495
+ :radix => 10,
496
+ :type_name => "",
497
+ :schema_name => "",
498
+ :sub_name => "",
499
+ :link => "",
500
+ #:type_metadata => nil,
501
+ :arguments => [],
502
+ :inspect => '#<OCI8::Metadata::Argument: ARG1 NUMBER(38)>',
503
+ },
504
+ [1] => {
505
+ :class => OCI8::Metadata::Argument,
506
+ :obj_id => nil,
507
+ :obj_name => nil,
508
+ :obj_schema => nil,
509
+ :name => "ARG2",
510
+ :position => 2,
511
+ #:typecode => nil,
512
+ :data_type => :varchar2,
513
+ :data_size => 0,
514
+ :precision => 0,
515
+ :scale => 0,
516
+ :level => 0,
517
+ :has_default => 0,
518
+ :has_default? => false,
519
+ :iomode => :out,
520
+ :radix => 0,
521
+ :type_name => "",
522
+ :schema_name => "",
523
+ :sub_name => "",
524
+ :link => "",
525
+ #:type_metadata => nil,
526
+ :arguments => [],
527
+ :inspect => '#<OCI8::Metadata::Argument: ARG2 VARCHAR2(0)>', # TODO: change to "VARCHAR2"
528
+ },
529
+ },
530
+ :is_standalone? => true,
531
+ :inspect => '#<OCI8::Metadata::Procedure: TEST_PROC>',
532
+ }
533
+ [
534
+ @conn.describe_any('test_proc'),
535
+ @conn.describe_procedure('test_proc'),
536
+ @conn.describe_schema(@conn.username).objects.detect do |obj|
537
+ obj.obj_name == 'TEST_PROC'
538
+ end
539
+ ].each do |desc|
540
+ check_attributes("line: #{__LINE__}", desc, attrs)
541
+ end
542
+
543
+ @conn.exec(<<-EOS)
544
+ CREATE OR REPLACE PROCEDURE test_proc(arg1 IN INTEGER, arg2 OUT varchar2)
545
+ AUTHID CURRENT_USER
546
+ IS
547
+ BEGIN
548
+ NULL;
549
+ END;
550
+ EOS
551
+ attrs = {
552
+ :class => OCI8::Metadata::Procedure,
553
+ :obj_id => to_obj_id(@conn.username, 'TEST_PROC'),
554
+ :obj_name => 'TEST_PROC',
555
+ :obj_schema => @conn.username,
556
+ :is_invoker_rights? => true,
557
+ :name => 'TEST_PROC',
558
+ :overload_id => nil,
559
+ :arguments => {
560
+ :class => Array,
561
+ :size => 2,
562
+ [0] => {
563
+ :class => OCI8::Metadata::Argument,
564
+ :obj_id => nil,
565
+ :obj_name => nil,
566
+ :obj_schema => nil,
567
+ :name => "ARG1",
568
+ :position => 1,
569
+ #:typecode => nil,
570
+ :data_type => :number,
571
+ :data_size => 22,
572
+ :precision => 38,
573
+ :scale => 0,
574
+ :level => 0,
575
+ :has_default => 0,
576
+ :has_default? => false,
577
+ :iomode => :in,
578
+ :radix => 10,
579
+ :type_name => "",
580
+ :schema_name => "",
581
+ :sub_name => "",
582
+ :link => "",
583
+ #:type_metadata => nil,
584
+ :arguments => [],
585
+ :inspect => '#<OCI8::Metadata::Argument: ARG1 NUMBER(38)>',
586
+ },
587
+ [1] => {
588
+ :class => OCI8::Metadata::Argument,
589
+ :obj_id => nil,
590
+ :obj_name => nil,
591
+ :obj_schema => nil,
592
+ :name => "ARG2",
593
+ :position => 2,
594
+ #:typecode => nil,
595
+ :data_type => :varchar2,
596
+ :data_size => 0,
597
+ :precision => 0,
598
+ :scale => 0,
599
+ :level => 0,
600
+ :has_default => 0,
601
+ :has_default? => false,
602
+ :iomode => :out,
603
+ :radix => 0,
604
+ :type_name => "",
605
+ :schema_name => "",
606
+ :sub_name => "",
607
+ :link => "",
608
+ #:type_metadata => nil,
609
+ :arguments => [],
610
+ :inspect => '#<OCI8::Metadata::Argument: ARG2 VARCHAR2(0)>', # TODO: change to "VARCHAR2"
611
+ },
612
+ },
613
+ :is_standalone? => true,
614
+ :inspect => '#<OCI8::Metadata::Procedure: TEST_PROC>',
615
+ }
616
+ [
617
+ @conn.describe_any('test_proc'),
618
+ @conn.describe_procedure('test_proc'),
619
+ @conn.describe_schema(@conn.username).objects.detect do |obj|
620
+ obj.obj_name == 'TEST_PROC'
621
+ end
622
+ ].each do |desc|
623
+ check_attributes("line: #{__LINE__}", desc, attrs)
624
+ end
625
+
626
+ @conn.exec('DROP PROCEDURE test_proc');
627
+
628
+ end # test_procedure_metadata
629
+
630
+ def test_function_metadata
631
+ @conn.exec(<<-EOS)
632
+ CREATE OR REPLACE FUNCTION test_func(arg1 IN INTEGER, arg2 OUT varchar2) RETURN NUMBER IS
633
+ BEGIN
634
+ RETURN arg1;
635
+ END;
636
+ EOS
637
+ attrs = {
638
+ :class => OCI8::Metadata::Function,
639
+ :obj_id => to_obj_id(@conn.username, 'TEST_FUNC'),
640
+ :obj_name => 'TEST_FUNC',
641
+ :obj_schema => @conn.username,
642
+ :is_invoker_rights? => false,
643
+ :name => 'TEST_FUNC',
644
+ :overload_id => nil,
645
+ :arguments => {
646
+ :class => Array,
647
+ :size => 3,
648
+ [0] => {
649
+ :class => OCI8::Metadata::Argument,
650
+ :obj_id => nil,
651
+ :obj_name => nil,
652
+ :obj_schema => nil,
653
+ :name => "",
654
+ :position => 0,
655
+ #:typecode => nil,
656
+ :data_type => :number,
657
+ :data_size => 22,
658
+ :precision => 0,
659
+ :scale => 0,
660
+ :level => 0,
661
+ :has_default => 0,
662
+ :has_default? => false,
663
+ :iomode => :out,
664
+ :radix => 10,
665
+ :type_name => "",
666
+ :schema_name => "",
667
+ :sub_name => "",
668
+ :link => "",
669
+ #:type_metadata => nil,
670
+ :arguments => [],
671
+ :inspect => '#<OCI8::Metadata::Argument: NUMBER>',
672
+ },
673
+ [1] => {
674
+ :class => OCI8::Metadata::Argument,
675
+ :obj_id => nil,
676
+ :obj_name => nil,
677
+ :obj_schema => nil,
678
+ :name => "ARG1",
679
+ :position => 1,
680
+ #:typecode => nil,
681
+ :data_type => :number,
682
+ :data_size => 22,
683
+ :precision => 38,
684
+ :scale => 0,
685
+ :level => 0,
686
+ :has_default => 0,
687
+ :has_default? => false,
688
+ :iomode => :in,
689
+ :radix => 10,
690
+ :type_name => "",
691
+ :schema_name => "",
692
+ :sub_name => "",
693
+ :link => "",
694
+ #:type_metadata => nil,
695
+ :arguments => [],
696
+ :inspect => '#<OCI8::Metadata::Argument: ARG1 NUMBER(38)>',
697
+ },
698
+ [2] => {
699
+ :class => OCI8::Metadata::Argument,
700
+ :obj_id => nil,
701
+ :obj_name => nil,
702
+ :obj_schema => nil,
703
+ :name => "ARG2",
704
+ :position => 2,
705
+ #:typecode => nil,
706
+ :data_type => :varchar2,
707
+ :data_size => 0,
708
+ :precision => 0,
709
+ :scale => 0,
710
+ :level => 0,
711
+ :has_default => 0,
712
+ :has_default? => false,
713
+ :iomode => :out,
714
+ :radix => 0,
715
+ :type_name => "",
716
+ :schema_name => "",
717
+ :sub_name => "",
718
+ :link => "",
719
+ #:type_metadata => nil,
720
+ :arguments => [],
721
+ :inspect => '#<OCI8::Metadata::Argument: ARG2 VARCHAR2(0)>', # TODO: change to "VARCHAR2"
722
+ },
723
+ },
724
+ :is_standalone? => true,
725
+ :inspect => '#<OCI8::Metadata::Function: TEST_FUNC>',
726
+ }
727
+ [
728
+ @conn.describe_any('test_func'),
729
+ @conn.describe_function('test_func'),
730
+ @conn.describe_schema(@conn.username).objects.detect do |obj|
731
+ obj.obj_name == 'TEST_FUNC'
732
+ end
733
+ ].each do |desc|
734
+ check_attributes("line: #{__LINE__}", desc, attrs)
735
+ end
736
+
737
+ @conn.exec(<<-EOS)
738
+ CREATE OR REPLACE FUNCTION test_func(arg1 IN INTEGER, arg2 OUT varchar2) RETURN NUMBER
739
+ AUTHID CURRENT_USER
740
+ IS
741
+ BEGIN
742
+ RETURN arg1;
743
+ END;
744
+ EOS
745
+ attrs = {
746
+ :class => OCI8::Metadata::Function,
747
+ :obj_id => to_obj_id(@conn.username, 'TEST_FUNC'),
748
+ :obj_name => 'TEST_FUNC',
749
+ :obj_schema => @conn.username,
750
+ :is_invoker_rights? => true,
751
+ :name => 'TEST_FUNC',
752
+ :overload_id => nil,
753
+ :arguments => {
754
+ :class => Array,
755
+ :size => 3,
756
+ [0] => {
757
+ :class => OCI8::Metadata::Argument,
758
+ :obj_id => nil,
759
+ :obj_name => nil,
760
+ :obj_schema => nil,
761
+ :name => "",
762
+ :position => 0,
763
+ #:typecode => nil,
764
+ :data_type => :number,
765
+ :data_size => 22,
766
+ :precision => 0,
767
+ :scale => 0,
768
+ :level => 0,
769
+ :has_default => 0,
770
+ :has_default? => false,
771
+ :iomode => :out,
772
+ :radix => 10,
773
+ :type_name => "",
774
+ :schema_name => "",
775
+ :sub_name => "",
776
+ :link => "",
777
+ #:type_metadata => nil,
778
+ :arguments => [],
779
+ :inspect => '#<OCI8::Metadata::Argument: NUMBER>',
780
+ },
781
+ [1] => {
782
+ :class => OCI8::Metadata::Argument,
783
+ :obj_id => nil,
784
+ :obj_name => nil,
785
+ :obj_schema => nil,
786
+ :name => "ARG1",
787
+ :position => 1,
788
+ #:typecode => nil,
789
+ :data_type => :number,
790
+ :data_size => 22,
791
+ :precision => 38,
792
+ :scale => 0,
793
+ :level => 0,
794
+ :has_default => 0,
795
+ :has_default? => false,
796
+ :iomode => :in,
797
+ :radix => 10,
798
+ :type_name => "",
799
+ :schema_name => "",
800
+ :sub_name => "",
801
+ :link => "",
802
+ #:type_metadata => nil,
803
+ :arguments => [],
804
+ :inspect => '#<OCI8::Metadata::Argument: ARG1 NUMBER(38)>',
805
+ },
806
+ [2] => {
807
+ :class => OCI8::Metadata::Argument,
808
+ :obj_id => nil,
809
+ :obj_name => nil,
810
+ :obj_schema => nil,
811
+ :name => "ARG2",
812
+ :position => 2,
813
+ #:typecode => nil,
814
+ :data_type => :varchar2,
815
+ :data_size => 0,
816
+ :precision => 0,
817
+ :scale => 0,
818
+ :level => 0,
819
+ :has_default => 0,
820
+ :has_default? => false,
821
+ :iomode => :out,
822
+ :radix => 0,
823
+ :type_name => "",
824
+ :schema_name => "",
825
+ :sub_name => "",
826
+ :link => "",
827
+ #:type_metadata => nil,
828
+ :arguments => [],
829
+ :inspect => '#<OCI8::Metadata::Argument: ARG2 VARCHAR2(0)>', # TODO: change to "VARCHAR2"
830
+ },
831
+ },
832
+ :is_standalone? => true,
833
+ :inspect => '#<OCI8::Metadata::Function: TEST_FUNC>',
834
+ }
835
+ [
836
+ @conn.describe_any('test_func'),
837
+ @conn.describe_function('test_func'),
838
+ @conn.describe_schema(@conn.username).objects.detect do |obj|
839
+ obj.obj_name == 'TEST_FUNC'
840
+ end
841
+ ].each do |desc|
842
+ check_attributes("line: #{__LINE__}", desc, attrs)
843
+ end
844
+
845
+ @conn.exec('DROP FUNCTION test_func');
846
+
847
+ end # test_function_metadata
848
+
849
+ def test_package_metadata
850
+ @conn.exec(<<-EOS)
851
+ CREATE OR REPLACE PACKAGE TEST_PKG IS
852
+ FUNCTION test_func(arg1 IN INTEGER, arg2 OUT varchar2) RETURN NUMBER;
853
+ PROCEDURE test_proc(arg1 IN INTEGER, arg2 OUT varchar2);
854
+ END;
855
+ EOS
856
+ attrs = {
857
+ :class => OCI8::Metadata::Package,
858
+ :obj_id => to_obj_id(@conn.username, 'TEST_PKG'),
859
+ :obj_name => 'TEST_PKG',
860
+ :obj_schema => @conn.username,
861
+ :is_invoker_rights? => false,
862
+ :subprograms => {
863
+ :class => Array,
864
+ :size => 2,
865
+ [0] => {
866
+ :class => OCI8::Metadata::Function,
867
+ :obj_id => nil,
868
+ :obj_name => 'TEST_FUNC',
869
+ :obj_schema => nil,
870
+ :is_invoker_rights? => false,
871
+ :name => 'TEST_FUNC',
872
+ :overload_id => 0,
873
+ :arguments => {
874
+ :class => Array,
875
+ :size => 3,
876
+ [0] => {
877
+ :class => OCI8::Metadata::Argument,
878
+ :obj_id => nil,
879
+ :obj_name => nil,
880
+ :obj_schema => nil,
881
+ :name => "",
882
+ :position => 0,
883
+ #:typecode => nil,
884
+ :data_type => :number,
885
+ :data_size => 22,
886
+ :precision => 0,
887
+ :scale => 0,
888
+ :level => 0,
889
+ :has_default => 0,
890
+ :has_default? => false,
891
+ :iomode => :out,
892
+ :radix => 10,
893
+ :type_name => "",
894
+ :schema_name => "",
895
+ :sub_name => "",
896
+ :link => "",
897
+ #:type_metadata => nil,
898
+ :arguments => [],
899
+ :inspect => '#<OCI8::Metadata::Argument: NUMBER>',
900
+ },
901
+ [1] => {
902
+ :class => OCI8::Metadata::Argument,
903
+ :obj_id => nil,
904
+ :obj_name => nil,
905
+ :obj_schema => nil,
906
+ :name => "ARG1",
907
+ :position => 1,
908
+ #:typecode => nil,
909
+ :data_type => :number,
910
+ :data_size => 22,
911
+ :precision => 38,
912
+ :scale => 0,
913
+ :level => 0,
914
+ :has_default => 0,
915
+ :has_default? => false,
916
+ :iomode => :in,
917
+ :radix => 10,
918
+ :type_name => "",
919
+ :schema_name => "",
920
+ :sub_name => "",
921
+ :link => "",
922
+ #:type_metadata => nil,
923
+ :arguments => [],
924
+ :inspect => '#<OCI8::Metadata::Argument: ARG1 NUMBER(38)>',
925
+ },
926
+ [2] => {
927
+ :class => OCI8::Metadata::Argument,
928
+ :obj_id => nil,
929
+ :obj_name => nil,
930
+ :obj_schema => nil,
931
+ :name => "ARG2",
932
+ :position => 2,
933
+ #:typecode => nil,
934
+ :data_type => :varchar2,
935
+ :data_size => 0,
936
+ :precision => 0,
937
+ :scale => 0,
938
+ :level => 0,
939
+ :has_default => 0,
940
+ :has_default? => false,
941
+ :iomode => :out,
942
+ :radix => 0,
943
+ :type_name => "",
944
+ :schema_name => "",
945
+ :sub_name => "",
946
+ :link => "",
947
+ #:type_metadata => nil,
948
+ :arguments => [],
949
+ :inspect => '#<OCI8::Metadata::Argument: ARG2 VARCHAR2(0)>', # TODO: change to "VARCHAR2"
950
+ },
951
+ },
952
+ :is_standalone? => false,
953
+ :inspect => '#<OCI8::Metadata::Function: TEST_FUNC>',
954
+ },
955
+ [1] => {
956
+ :class => OCI8::Metadata::Procedure,
957
+ :obj_id => nil,
958
+ :obj_name => 'TEST_PROC',
959
+ :obj_schema => nil,
960
+ :is_invoker_rights? => false,
961
+ :name => 'TEST_PROC',
962
+ :overload_id => 0,
963
+ :arguments => {
964
+ :class => Array,
965
+ :size => 2,
966
+ [0] => {
967
+ :class => OCI8::Metadata::Argument,
968
+ :obj_id => nil,
969
+ :obj_name => nil,
970
+ :obj_schema => nil,
971
+ :name => "ARG1",
972
+ :position => 1,
973
+ #:typecode => nil,
974
+ :data_type => :number,
975
+ :data_size => 22,
976
+ :precision => 38,
977
+ :scale => 0,
978
+ :level => 0,
979
+ :has_default => 0,
980
+ :has_default? => false,
981
+ :iomode => :in,
982
+ :radix => 10,
983
+ :type_name => "",
984
+ :schema_name => "",
985
+ :sub_name => "",
986
+ :link => "",
987
+ #:type_metadata => nil,
988
+ :arguments => [],
989
+ :inspect => '#<OCI8::Metadata::Argument: ARG1 NUMBER(38)>',
990
+ },
991
+ [1] => {
992
+ :class => OCI8::Metadata::Argument,
993
+ :obj_id => nil,
994
+ :obj_name => nil,
995
+ :obj_schema => nil,
996
+ :name => "ARG2",
997
+ :position => 2,
998
+ #:typecode => nil,
999
+ :data_type => :varchar2,
1000
+ :data_size => 0,
1001
+ :precision => 0,
1002
+ :scale => 0,
1003
+ :level => 0,
1004
+ :has_default => 0,
1005
+ :has_default? => false,
1006
+ :iomode => :out,
1007
+ :radix => 0,
1008
+ :type_name => "",
1009
+ :schema_name => "",
1010
+ :sub_name => "",
1011
+ :link => "",
1012
+ #:type_metadata => nil,
1013
+ :arguments => [],
1014
+ :inspect => '#<OCI8::Metadata::Argument: ARG2 VARCHAR2(0)>', # TODO: change to "VARCHAR2"
1015
+ },
1016
+ },
1017
+ :is_standalone? => false,
1018
+ :inspect => '#<OCI8::Metadata::Procedure: TEST_PROC>',
1019
+ },
1020
+ },
1021
+ :types => ($oracle_version >= OCI8::ORAVER_12_1) ? [] : :skip,
1022
+ :inspect => /#<OCI8::Metadata::Package:\(\d+\) #{@conn.username}.TEST_PKG>/,
1023
+ }
1024
+ [
1025
+ @conn.describe_any('test_pkg'),
1026
+ @conn.describe_package('test_pkg'),
1027
+ @conn.describe_schema(@conn.username).objects.detect do |obj|
1028
+ obj.obj_name == 'TEST_PKG'
1029
+ end
1030
+ ].each do |desc|
1031
+ check_attributes("line: #{__LINE__}", desc, attrs)
1032
+ end
1033
+
1034
+ @conn.exec(<<-EOS)
1035
+ CREATE OR REPLACE PACKAGE TEST_PKG AUTHID CURRENT_USER IS
1036
+ PROCEDURE test_proc(arg1 IN INTEGER, arg2 OUT varchar2);
1037
+ PROCEDURE test_proc(arg1 IN INTEGER);
1038
+ FUNCTION test_func(arg1 IN INTEGER, arg2 OUT varchar2) RETURN NUMBER;
1039
+ FUNCTION test_func(arg1 IN INTEGER) RETURN NUMBER;
1040
+ END;
1041
+ EOS
1042
+ attrs = {
1043
+ :class => OCI8::Metadata::Package,
1044
+ :obj_id => to_obj_id(@conn.username, 'TEST_PKG'),
1045
+ :obj_name => 'TEST_PKG',
1046
+ :obj_schema => @conn.username,
1047
+ :is_invoker_rights? => true,
1048
+ :subprograms => {
1049
+ :class => Array,
1050
+ :size => 4,
1051
+ [0] => {
1052
+ :class => OCI8::Metadata::Function,
1053
+ :obj_id => nil,
1054
+ :obj_name => 'TEST_FUNC',
1055
+ :obj_schema => nil,
1056
+ :is_invoker_rights? => true,
1057
+ :name => 'TEST_FUNC',
1058
+ :overload_id => 2,
1059
+ :arguments => {
1060
+ :class => Array,
1061
+ :size => 3,
1062
+ [0] => {
1063
+ :class => OCI8::Metadata::Argument,
1064
+ :obj_id => nil,
1065
+ :obj_name => nil,
1066
+ :obj_schema => nil,
1067
+ :name => "",
1068
+ :position => 0,
1069
+ #:typecode => nil,
1070
+ :data_type => :number,
1071
+ :data_size => 22,
1072
+ :precision => 0,
1073
+ :scale => 0,
1074
+ :level => 0,
1075
+ :has_default => 0,
1076
+ :has_default? => false,
1077
+ :iomode => :out,
1078
+ :radix => 10,
1079
+ :type_name => "",
1080
+ :schema_name => "",
1081
+ :sub_name => "",
1082
+ :link => "",
1083
+ #:type_metadata => nil,
1084
+ :arguments => [],
1085
+ :inspect => '#<OCI8::Metadata::Argument: NUMBER>',
1086
+ },
1087
+ [1] => {
1088
+ :class => OCI8::Metadata::Argument,
1089
+ :obj_id => nil,
1090
+ :obj_name => nil,
1091
+ :obj_schema => nil,
1092
+ :name => "ARG1",
1093
+ :position => 1,
1094
+ #:typecode => nil,
1095
+ :data_type => :number,
1096
+ :data_size => 22,
1097
+ :precision => 38,
1098
+ :scale => 0,
1099
+ :level => 0,
1100
+ :has_default => 0,
1101
+ :has_default? => false,
1102
+ :iomode => :in,
1103
+ :radix => 10,
1104
+ :type_name => "",
1105
+ :schema_name => "",
1106
+ :sub_name => "",
1107
+ :link => "",
1108
+ #:type_metadata => nil,
1109
+ :arguments => [],
1110
+ :inspect => '#<OCI8::Metadata::Argument: ARG1 NUMBER(38)>',
1111
+ },
1112
+ [2] => {
1113
+ :class => OCI8::Metadata::Argument,
1114
+ :obj_id => nil,
1115
+ :obj_name => nil,
1116
+ :obj_schema => nil,
1117
+ :name => "ARG2",
1118
+ :position => 2,
1119
+ #:typecode => nil,
1120
+ :data_type => :varchar2,
1121
+ :data_size => 0,
1122
+ :precision => 0,
1123
+ :scale => 0,
1124
+ :level => 0,
1125
+ :has_default => 0,
1126
+ :has_default? => false,
1127
+ :iomode => :out,
1128
+ :radix => 0,
1129
+ :type_name => "",
1130
+ :schema_name => "",
1131
+ :sub_name => "",
1132
+ :link => "",
1133
+ #:type_metadata => nil,
1134
+ :arguments => [],
1135
+ :inspect => '#<OCI8::Metadata::Argument: ARG2 VARCHAR2(0)>', # TODO: change to "VARCHAR2"
1136
+ },
1137
+ },
1138
+ :is_standalone? => false,
1139
+ :inspect => '#<OCI8::Metadata::Function: TEST_FUNC>',
1140
+ },
1141
+ [1] => {
1142
+ :class => OCI8::Metadata::Function,
1143
+ :obj_id => nil,
1144
+ :obj_name => 'TEST_FUNC',
1145
+ :obj_schema => nil,
1146
+ :is_invoker_rights? => true,
1147
+ :name => 'TEST_FUNC',
1148
+ :overload_id => 1,
1149
+ :arguments => {
1150
+ :class => Array,
1151
+ :size => 2,
1152
+ [0] => {
1153
+ :class => OCI8::Metadata::Argument,
1154
+ :obj_id => nil,
1155
+ :obj_name => nil,
1156
+ :obj_schema => nil,
1157
+ :name => "",
1158
+ :position => 0,
1159
+ #:typecode => nil,
1160
+ :data_type => :number,
1161
+ :data_size => 22,
1162
+ :precision => 0,
1163
+ :scale => 0,
1164
+ :level => 0,
1165
+ :has_default => 0,
1166
+ :has_default? => false,
1167
+ :iomode => :out,
1168
+ :radix => 10,
1169
+ :type_name => "",
1170
+ :schema_name => "",
1171
+ :sub_name => "",
1172
+ :link => "",
1173
+ #:type_metadata => nil,
1174
+ :arguments => [],
1175
+ :inspect => '#<OCI8::Metadata::Argument: NUMBER>',
1176
+ },
1177
+ [1] => {
1178
+ :class => OCI8::Metadata::Argument,
1179
+ :obj_id => nil,
1180
+ :obj_name => nil,
1181
+ :obj_schema => nil,
1182
+ :name => "ARG1",
1183
+ :position => 1,
1184
+ #:typecode => nil,
1185
+ :data_type => :number,
1186
+ :data_size => 22,
1187
+ :precision => 38,
1188
+ :scale => 0,
1189
+ :level => 0,
1190
+ :has_default => 0,
1191
+ :has_default? => false,
1192
+ :iomode => :in,
1193
+ :radix => 10,
1194
+ :type_name => "",
1195
+ :schema_name => "",
1196
+ :sub_name => "",
1197
+ :link => "",
1198
+ #:type_metadata => nil,
1199
+ :arguments => [],
1200
+ :inspect => '#<OCI8::Metadata::Argument: ARG1 NUMBER(38)>',
1201
+ },
1202
+ },
1203
+ :is_standalone? => false,
1204
+ :inspect => '#<OCI8::Metadata::Function: TEST_FUNC>',
1205
+ },
1206
+ [2] => {
1207
+ :class => OCI8::Metadata::Procedure,
1208
+ :obj_id => nil,
1209
+ :obj_name => 'TEST_PROC',
1210
+ :obj_schema => nil,
1211
+ :is_invoker_rights? => true,
1212
+ :name => 'TEST_PROC',
1213
+ :overload_id => 2,
1214
+ :arguments => {
1215
+ :class => Array,
1216
+ :size => 2,
1217
+ [0] => {
1218
+ :class => OCI8::Metadata::Argument,
1219
+ :obj_id => nil,
1220
+ :obj_name => nil,
1221
+ :obj_schema => nil,
1222
+ :name => "ARG1",
1223
+ :position => 1,
1224
+ #:typecode => nil,
1225
+ :data_type => :number,
1226
+ :data_size => 22,
1227
+ :precision => 38,
1228
+ :scale => 0,
1229
+ :level => 0,
1230
+ :has_default => 0,
1231
+ :has_default? => false,
1232
+ :iomode => :in,
1233
+ :radix => 10,
1234
+ :type_name => "",
1235
+ :schema_name => "",
1236
+ :sub_name => "",
1237
+ :link => "",
1238
+ #:type_metadata => nil,
1239
+ :arguments => [],
1240
+ :inspect => '#<OCI8::Metadata::Argument: ARG1 NUMBER(38)>',
1241
+ },
1242
+ [1] => {
1243
+ :class => OCI8::Metadata::Argument,
1244
+ :obj_id => nil,
1245
+ :obj_name => nil,
1246
+ :obj_schema => nil,
1247
+ :name => "ARG2",
1248
+ :position => 2,
1249
+ #:typecode => nil,
1250
+ :data_type => :varchar2,
1251
+ :data_size => 0,
1252
+ :precision => 0,
1253
+ :scale => 0,
1254
+ :level => 0,
1255
+ :has_default => 0,
1256
+ :has_default? => false,
1257
+ :iomode => :out,
1258
+ :radix => 0,
1259
+ :type_name => "",
1260
+ :schema_name => "",
1261
+ :sub_name => "",
1262
+ :link => "",
1263
+ #:type_metadata => nil,
1264
+ :arguments => [],
1265
+ :inspect => '#<OCI8::Metadata::Argument: ARG2 VARCHAR2(0)>', # TODO: change to "VARCHAR2"
1266
+ },
1267
+ },
1268
+ :is_standalone? => false,
1269
+ :inspect => '#<OCI8::Metadata::Procedure: TEST_PROC>',
1270
+ },
1271
+ [3] => {
1272
+ :class => OCI8::Metadata::Procedure,
1273
+ :obj_id => nil,
1274
+ :obj_name => 'TEST_PROC',
1275
+ :obj_schema => nil,
1276
+ :is_invoker_rights? => true,
1277
+ :name => 'TEST_PROC',
1278
+ :overload_id => 1,
1279
+ :arguments => {
1280
+ :class => Array,
1281
+ :size => 1,
1282
+ [0] => {
1283
+ :class => OCI8::Metadata::Argument,
1284
+ :obj_id => nil,
1285
+ :obj_name => nil,
1286
+ :obj_schema => nil,
1287
+ :name => "ARG1",
1288
+ :position => 1,
1289
+ #:typecode => nil,
1290
+ :data_type => :number,
1291
+ :data_size => 22,
1292
+ :precision => 38,
1293
+ :scale => 0,
1294
+ :level => 0,
1295
+ :has_default => 0,
1296
+ :has_default? => false,
1297
+ :iomode => :in,
1298
+ :radix => 10,
1299
+ :type_name => "",
1300
+ :schema_name => "",
1301
+ :sub_name => "",
1302
+ :link => "",
1303
+ #:type_metadata => nil,
1304
+ :arguments => [],
1305
+ :inspect => '#<OCI8::Metadata::Argument: ARG1 NUMBER(38)>',
1306
+ },
1307
+ },
1308
+ :is_standalone? => false,
1309
+ :inspect => '#<OCI8::Metadata::Procedure: TEST_PROC>',
1310
+ },
1311
+ },
1312
+ :types => ($oracle_version >= OCI8::ORAVER_12_1) ? [] : :skip,
1313
+ :inspect => /#<OCI8::Metadata::Package:\(\d+\) #{@conn.username}.TEST_PKG>/,
1314
+ }
1315
+ [
1316
+ @conn.describe_any('test_pkg'),
1317
+ @conn.describe_package('test_pkg'),
1318
+ @conn.describe_schema(@conn.username).objects.detect do |obj|
1319
+ obj.obj_name == 'TEST_PKG'
1320
+ end
1321
+ ].each do |desc|
1322
+ check_attributes("line: #{__LINE__}", desc, attrs)
1323
+ end
1324
+
1325
+ end # test_package_metadata
1326
+
1327
+ def test_type_metadata
1328
+ drop_type('TEST_TYPE_ORDER_METHOD')
1329
+ drop_type('TEST_TYPE_MAP_METHOD')
1330
+ drop_type('TEST_TYPE_HAS_BFILE')
1331
+ drop_type('TEST_TYPE_HAS_BLOB')
1332
+ drop_type('TEST_TYPE_HAS_NCLOB')
1333
+ drop_type('TEST_TYPE_HAS_CLOB')
1334
+ drop_type('TEST_TYPE_INCOMPLETE')
1335
+ drop_type('TEST_TYPE_GRANDCHILD')
1336
+ drop_type('TEST_TYPE_VARRAY')
1337
+ drop_type('TEST_TYPE_NESTEAD_TABLE')
1338
+ drop_type('TEST_TYPE_CHILD')
1339
+ drop_type('TEST_TYPE_PARENT')
1340
+ attrs_map = {}
1341
+
1342
+ @conn.exec(<<-EOS)
1343
+ CREATE TYPE test_type_parent AS OBJECT (
1344
+ col1 number(38,0),
1345
+ col2 varchar2(60)
1346
+ )
1347
+ NOT INSTANTIABLE
1348
+ NOT FINAL
1349
+ EOS
1350
+ attrs_map['TEST_TYPE_PARENT'] = {
1351
+ :class => OCI8::Metadata::Type,
1352
+ :obj_id => to_obj_id(@conn.username, 'TEST_TYPE_PARENT'),
1353
+ :obj_name => 'TEST_TYPE_PARENT',
1354
+ :obj_schema => @conn.username,
1355
+ :typecode => :named_type,
1356
+ :collection_typecode => nil,
1357
+ :is_incomplete_type? => false,
1358
+ :is_system_type? => false,
1359
+ :is_predefined_type? => false,
1360
+ :is_transient_type? => false,
1361
+ :is_system_generated_type? => false,
1362
+ :has_nested_table? => false,
1363
+ :has_lob? => false,
1364
+ :has_file? => false,
1365
+ :collection_element => nil,
1366
+ :num_type_attrs => 2,
1367
+ :num_type_methods => 0,
1368
+ :map_method => nil,
1369
+ :order_method => nil,
1370
+ :is_invoker_rights? => false,
1371
+ :name => 'TEST_TYPE_PARENT',
1372
+ :schema_name => @conn.username,
1373
+ :is_final_type? => false,
1374
+ :is_instantiable_type? => false,
1375
+ :is_subtype? => false,
1376
+ :supertype_schema_name => nil,
1377
+ :supertype_name => nil,
1378
+ :package_name => nil,
1379
+ :type_attrs => {
1380
+ :class => Array,
1381
+ :size => 2,
1382
+ [0] => {
1383
+ :class => OCI8::Metadata::TypeAttr,
1384
+ :inspect => '#<OCI8::Metadata::TypeAttr: COL1 NUMBER(38)>',
1385
+ },
1386
+ [1] => {
1387
+ :class => OCI8::Metadata::TypeAttr,
1388
+ :inspect => '#<OCI8::Metadata::TypeAttr: COL2 VARCHAR2(60)>',
1389
+ },
1390
+ },
1391
+ :type_methods => [],
1392
+ :inspect => /#<OCI8::Metadata::Type:\(\d+\) #{@conn.username}.TEST_TYPE_PARENT>/,
1393
+ }
1394
+ @conn.exec(<<-EOS)
1395
+ CREATE TYPE test_type_child UNDER test_type_parent (
1396
+ lob BLOB
1397
+ )
1398
+ NOT FINAL
1399
+ EOS
1400
+ attrs_map['TEST_TYPE_CHILD'] = {
1401
+ :class => OCI8::Metadata::Type,
1402
+ :obj_id => to_obj_id(@conn.username, 'TEST_TYPE_CHILD'),
1403
+ :obj_name => 'TEST_TYPE_CHILD',
1404
+ :obj_schema => @conn.username,
1405
+ :typecode => :named_type,
1406
+ :collection_typecode => nil,
1407
+ :is_incomplete_type? => false,
1408
+ :is_system_type? => false,
1409
+ :is_predefined_type? => false,
1410
+ :is_transient_type? => false,
1411
+ :is_system_generated_type? => false,
1412
+ :has_nested_table? => false,
1413
+ :has_lob? => true,
1414
+ :has_file? => false,
1415
+ :collection_element => nil,
1416
+ :num_type_attrs => 3,
1417
+ :num_type_methods => 0,
1418
+ :map_method => nil,
1419
+ :order_method => nil,
1420
+ :is_invoker_rights? => false,
1421
+ :name => 'TEST_TYPE_CHILD',
1422
+ :schema_name => @conn.username,
1423
+ :is_final_type? => false,
1424
+ :is_instantiable_type? => true,
1425
+ :is_subtype? => true,
1426
+ :supertype_schema_name => @conn.username,
1427
+ :supertype_name => 'TEST_TYPE_PARENT',
1428
+ :package_name => nil,
1429
+ :type_attrs => {
1430
+ :class => Array,
1431
+ :size => 3,
1432
+ [0] => attrs_map['TEST_TYPE_PARENT'][:type_attrs][[0]],
1433
+ [1] => attrs_map['TEST_TYPE_PARENT'][:type_attrs][[1]],
1434
+ [2] => {
1435
+ :class => OCI8::Metadata::TypeAttr,
1436
+ :inspect => '#<OCI8::Metadata::TypeAttr: LOB BLOB>',
1437
+ },
1438
+ },
1439
+ :type_methods => [],
1440
+ :inspect => /#<OCI8::Metadata::Type:\(\d+\) #{@conn.username}.TEST_TYPE_CHILD>/,
1441
+ }
1442
+ @conn.exec(<<-EOS)
1443
+ CREATE TYPE test_type_nestead_table AS TABLE OF test_type_child
1444
+ EOS
1445
+ attrs_map['TEST_TYPE_NESTEAD_TABLE'] = {
1446
+ :class => OCI8::Metadata::Type,
1447
+ :obj_id => to_obj_id(@conn.username, 'TEST_TYPE_NESTEAD_TABLE'),
1448
+ :obj_name => 'TEST_TYPE_NESTEAD_TABLE',
1449
+ :obj_schema => @conn.username,
1450
+ :typecode => :named_collection,
1451
+ :collection_typecode => :table,
1452
+ :is_incomplete_type? => false,
1453
+ :is_system_type? => false,
1454
+ :is_predefined_type? => false,
1455
+ :is_transient_type? => false,
1456
+ :is_system_generated_type? => false,
1457
+ :has_nested_table? => true,
1458
+ :has_lob? => true,
1459
+ :has_file? => false,
1460
+ :collection_element => {
1461
+ :class => OCI8::Metadata::Collection,
1462
+ :obj_id => nil,
1463
+ :obj_name => nil,
1464
+ :obj_schema => nil,
1465
+ :data_size => 0,
1466
+ :typecode => :named_type,
1467
+ :data_type => :named_type,
1468
+ :num_elems => 0,
1469
+ :precision => 0,
1470
+ :scale => 0,
1471
+ :type_name => 'TEST_TYPE_CHILD',
1472
+ :schema_name => @conn.username,
1473
+ :type_metadata => {
1474
+ :class => OCI8::Metadata::Type,
1475
+ :obj_id => 0,
1476
+ :obj_name => nil,
1477
+ :obj_schema => nil,
1478
+ :typecode => :named_type,
1479
+ :collection_typecode => nil,
1480
+ :is_incomplete_type? => false,
1481
+ :is_system_type? => false,
1482
+ :is_predefined_type? => false,
1483
+ :is_transient_type? => false,
1484
+ :is_system_generated_type? => false,
1485
+ :has_nested_table? => false,
1486
+ :has_lob? => true,
1487
+ :has_file? => false,
1488
+ :collection_element => nil,
1489
+ :num_type_attrs => 3,
1490
+ :num_type_methods => 0,
1491
+ :map_method => nil,
1492
+ :order_method => nil,
1493
+ :is_invoker_rights? => false,
1494
+ :name => 'TEST_TYPE_CHILD',
1495
+ :schema_name => @conn.username,
1496
+ :is_final_type? => false,
1497
+ :is_instantiable_type? => true,
1498
+ :is_subtype? => true,
1499
+ :supertype_schema_name => @conn.username,
1500
+ :supertype_name => 'TEST_TYPE_PARENT',
1501
+ :package_name => nil,
1502
+ :type_attrs => {
1503
+ :class => Array,
1504
+ :size => 3,
1505
+ [0] => {
1506
+ :class => OCI8::Metadata::TypeAttr,
1507
+ :inspect => '#<OCI8::Metadata::TypeAttr: COL1 NUMBER(38)>',
1508
+ },
1509
+ [1] => {
1510
+ :class => OCI8::Metadata::TypeAttr,
1511
+ :inspect => '#<OCI8::Metadata::TypeAttr: COL2 VARCHAR2(60)>',
1512
+ },
1513
+ [2] => {
1514
+ :class => OCI8::Metadata::TypeAttr,
1515
+ :inspect => '#<OCI8::Metadata::TypeAttr: LOB BLOB>',
1516
+ },
1517
+ },
1518
+ :inspect => "#<OCI8::Metadata::Type:(0) #{@conn.username}.TEST_TYPE_CHILD>",
1519
+ },
1520
+ :inspect => "#<OCI8::Metadata::Collection: #{@conn.username}.TEST_TYPE_CHILD>",
1521
+ },
1522
+ :num_type_attrs => 0,
1523
+ :num_type_methods => 0,
1524
+ :map_method => nil,
1525
+ :order_method => nil,
1526
+ :is_invoker_rights? => false,
1527
+ :name => 'TEST_TYPE_NESTEAD_TABLE',
1528
+ :schema_name => @conn.username,
1529
+ :is_final_type? => true,
1530
+ :is_instantiable_type? => true,
1531
+ :is_subtype? => false,
1532
+ :supertype_schema_name => nil,
1533
+ :supertype_name => nil,
1534
+ :package_name => nil,
1535
+ :type_attrs => [],
1536
+ :type_methods => [],
1537
+ :inspect => /#<OCI8::Metadata::Type:\(\d+\) #{@conn.username}.TEST_TYPE_NESTEAD_TABLE>/,
1538
+ }
1539
+ @conn.exec(<<-EOS)
1540
+ CREATE TYPE test_type_varray AS VARRAY(10) OF test_type_child
1541
+ EOS
1542
+ attrs_map['TEST_TYPE_VARRAY'] = {
1543
+ :class => OCI8::Metadata::Type,
1544
+ :obj_id => to_obj_id(@conn.username, 'TEST_TYPE_VARRAY'),
1545
+ :obj_name => 'TEST_TYPE_VARRAY',
1546
+ :obj_schema => @conn.username,
1547
+ :typecode => :named_collection,
1548
+ :collection_typecode => :varray,
1549
+ :is_incomplete_type? => false,
1550
+ :is_system_type? => false,
1551
+ :is_predefined_type? => false,
1552
+ :is_transient_type? => false,
1553
+ :is_system_generated_type? => false,
1554
+ :has_nested_table? => false,
1555
+ :has_lob? => true,
1556
+ :has_file? => false,
1557
+ :collection_element => {
1558
+ :class => OCI8::Metadata::Collection,
1559
+ :obj_id => nil,
1560
+ :obj_name => nil,
1561
+ :obj_schema => nil,
1562
+ :data_size => 0,
1563
+ :typecode => :named_type,
1564
+ :data_type => :named_type,
1565
+ :num_elems => 10,
1566
+ :precision => 0,
1567
+ :scale => 0,
1568
+ :type_name => 'TEST_TYPE_CHILD',
1569
+ :schema_name => @conn.username,
1570
+ :type_metadata => attrs_map['TEST_TYPE_NESTEAD_TABLE'][:collection_element][:type_metadata],
1571
+ :inspect => "#<OCI8::Metadata::Collection: #{@conn.username}.TEST_TYPE_CHILD>",
1572
+ },
1573
+ :num_type_attrs => 0,
1574
+ :num_type_methods => 0,
1575
+ :map_method => nil,
1576
+ :order_method => nil,
1577
+ :is_invoker_rights? => false,
1578
+ :name => 'TEST_TYPE_VARRAY',
1579
+ :schema_name => @conn.username,
1580
+ :is_final_type? => true,
1581
+ :is_instantiable_type? => true,
1582
+ :is_subtype? => false,
1583
+ :supertype_schema_name => nil,
1584
+ :supertype_name => nil,
1585
+ :package_name => nil,
1586
+ :type_attrs => [],
1587
+ :type_methods => [],
1588
+ :inspect => /#<OCI8::Metadata::Type:\(\d+\) #{@conn.username}.TEST_TYPE_VARRAY>/,
1589
+ }
1590
+ @conn.exec(<<-EOS)
1591
+ CREATE TYPE test_type_grandchild UNDER test_type_child (
1592
+ table_column test_type_nestead_table,
1593
+ file_column BFILE
1594
+ )
1595
+ EOS
1596
+ attrs_map['TEST_TYPE_GRANDCHILD'] = {
1597
+ :class => OCI8::Metadata::Type,
1598
+ :obj_id => to_obj_id(@conn.username, 'TEST_TYPE_GRANDCHILD'),
1599
+ :obj_name => 'TEST_TYPE_GRANDCHILD',
1600
+ :obj_schema => @conn.username,
1601
+ :typecode => :named_type,
1602
+ :collection_typecode => nil,
1603
+ :is_incomplete_type? => false,
1604
+ :is_system_type? => false,
1605
+ :is_predefined_type? => false,
1606
+ :is_transient_type? => false,
1607
+ :is_system_generated_type? => false,
1608
+ :has_nested_table? => true,
1609
+ :has_lob? => true,
1610
+ :has_file? => true,
1611
+ :collection_element => nil,
1612
+ :num_type_attrs => 5,
1613
+ :num_type_methods => 0,
1614
+ :map_method => nil,
1615
+ :order_method => nil,
1616
+ :is_invoker_rights? => false,
1617
+ :name => 'TEST_TYPE_GRANDCHILD',
1618
+ :schema_name => @conn.username,
1619
+ :is_final_type? => true,
1620
+ :is_instantiable_type? => true,
1621
+ :is_subtype? => true,
1622
+ :supertype_schema_name => @conn.username,
1623
+ :supertype_name => 'TEST_TYPE_CHILD',
1624
+ :package_name => nil,
1625
+ :type_attrs => {
1626
+ :class => Array,
1627
+ :size => 5,
1628
+ [0] => attrs_map['TEST_TYPE_CHILD'][:type_attrs][[0]],
1629
+ [1] => attrs_map['TEST_TYPE_CHILD'][:type_attrs][[1]],
1630
+ [2] => attrs_map['TEST_TYPE_CHILD'][:type_attrs][[2]],
1631
+ [3] => {
1632
+ :class => OCI8::Metadata::TypeAttr,
1633
+ :inspect => "#<OCI8::Metadata::TypeAttr: TABLE_COLUMN #{@conn.username}.TEST_TYPE_NESTEAD_TABLE>",
1634
+ },
1635
+ [4] => {
1636
+ :class => OCI8::Metadata::TypeAttr,
1637
+ :inspect => '#<OCI8::Metadata::TypeAttr: FILE_COLUMN BFILE>',
1638
+ },
1639
+ },
1640
+ :type_methods => [],
1641
+ :inspect => /#<OCI8::Metadata::Type:\(\d+\) #{@conn.username}.TEST_TYPE_GRANDCHILD>/,
1642
+ }
1643
+ @conn.exec(<<-EOS)
1644
+ CREATE TYPE test_type_incomplete
1645
+ EOS
1646
+ attrs_map['TEST_TYPE_INCOMPLETE'] = {
1647
+ :class => OCI8::Metadata::Type,
1648
+ :obj_id => to_obj_id(@conn.username, 'TEST_TYPE_INCOMPLETE'),
1649
+ :obj_name => 'TEST_TYPE_INCOMPLETE',
1650
+ :obj_schema => @conn.username,
1651
+ :typecode => :named_type,
1652
+ :collection_typecode => nil,
1653
+ :is_incomplete_type? => true,
1654
+ :is_system_type? => false,
1655
+ :is_predefined_type? => false,
1656
+ :is_transient_type? => false,
1657
+ :is_system_generated_type? => false,
1658
+ :has_nested_table? => false,
1659
+ :has_lob? => false,
1660
+ :has_file? => false,
1661
+ :collection_element => nil,
1662
+ :num_type_attrs => 0,
1663
+ :num_type_methods => 0,
1664
+ :map_method => nil,
1665
+ :order_method => nil,
1666
+ :is_invoker_rights? => false,
1667
+ :name => 'TEST_TYPE_INCOMPLETE',
1668
+ :schema_name => @conn.username,
1669
+ :is_final_type? => true,
1670
+ :is_instantiable_type? => true,
1671
+ :is_subtype? => false,
1672
+ :supertype_schema_name => nil,
1673
+ :supertype_name => nil,
1674
+ :package_name => nil,
1675
+ :type_attrs => [],
1676
+ :type_methods => [],
1677
+ :inspect => /#<OCI8::Metadata::Type:\(\d+\) #{@conn.username}.TEST_TYPE_INCOMPLETE>/,
1678
+ }
1679
+ @conn.exec(<<-EOS)
1680
+ CREATE TYPE test_type_has_clob AS OBJECT (lob CLOB)
1681
+ EOS
1682
+ attrs_map['TEST_TYPE_HAS_CLOB'] = {
1683
+ :class => OCI8::Metadata::Type,
1684
+ :has_lob? => true,
1685
+ :has_file? => false,
1686
+ }
1687
+ if $oracle_version >= OCI8::ORAVER_9_2
1688
+ @conn.exec(<<-EOS)
1689
+ CREATE TYPE test_type_has_nclob AS OBJECT (lob NCLOB)
1690
+ EOS
1691
+ attrs_map['TEST_TYPE_HAS_NCLOB'] = {
1692
+ :class => OCI8::Metadata::Type,
1693
+ :has_lob? => true,
1694
+ :has_file? => false,
1695
+ }
1696
+ end
1697
+ @conn.exec(<<-EOS)
1698
+ CREATE TYPE test_type_has_blob AS OBJECT (lob BLOB)
1699
+ EOS
1700
+ attrs_map['TEST_TYPE_HAS_BLOB'] = {
1701
+ :class => OCI8::Metadata::Type,
1702
+ :has_lob? => true,
1703
+ :has_file? => false,
1704
+ }
1705
+ @conn.exec(<<-EOS)
1706
+ CREATE TYPE test_type_has_bfile AS OBJECT (lob BFILE)
1707
+ EOS
1708
+ attrs_map['TEST_TYPE_HAS_BFILE'] = {
1709
+ :class => OCI8::Metadata::Type,
1710
+ :has_lob? => false,
1711
+ :has_file? => true,
1712
+ }
1713
+ @conn.exec(<<-EOS)
1714
+ CREATE TYPE test_type_map_method AS OBJECT (
1715
+ x integer,
1716
+ y integer,
1717
+ MAP MEMBER FUNCTION area RETURN NUMBER
1718
+ )
1719
+ EOS
1720
+ attrs_map['TEST_TYPE_MAP_METHOD'] = {
1721
+ :class => OCI8::Metadata::Type,
1722
+ :map_method => {
1723
+ :class => OCI8::Metadata::TypeMethod,
1724
+ :name => 'AREA',
1725
+ :encapsulation => :public,
1726
+ :has_result? => true,
1727
+ :is_constructor? => false,
1728
+ :is_destructor? => false,
1729
+ :is_operator? => false,
1730
+ :is_selfish? => true,
1731
+ :is_map? => true,
1732
+ :is_order? => false,
1733
+ :is_rnds? => true,
1734
+ :is_rnps? => true,
1735
+ :is_wnds? => true,
1736
+ :is_wnps? => true,
1737
+ :is_final_method? => false,
1738
+ :is_instantiable_method? => true,
1739
+ :is_overriding_method? => false,
1740
+ :arguments => {
1741
+ :class => Array,
1742
+ :size => 1,
1743
+ [0] => {
1744
+ :class => OCI8::Metadata::TypeArgument,
1745
+ :obj_id => nil,
1746
+ :obj_name => nil,
1747
+ :obj_schema => nil,
1748
+ :name => "SELF",
1749
+ :position => 1,
1750
+ #:typecode => nil,
1751
+ :data_type => :named_type,
1752
+ #:data_size => 0, # ORA-24328: illegal attribute value
1753
+ #:precision => 0, # ORA-24328: illegal attribute value
1754
+ #:scale => 0, # ORA-24328: illegal attribute value
1755
+ :level => 0,
1756
+ :has_default => 0,
1757
+ :has_default? => false,
1758
+ :iomode => :in,
1759
+ #:radix => 0, # ORA-24328: illegal attribute value
1760
+ :type_name => "TEST_TYPE_MAP_METHOD",
1761
+ :schema_name => @conn.username,
1762
+ #:sub_name => nil, # ORA-24328: illegal attribute value
1763
+ #:link => nil, # ORA-24328: illegal attribute value
1764
+ :type_metadata => {
1765
+ :class => OCI8::Metadata::Type,
1766
+ :inspect => "#<OCI8::Metadata::Type:(0) #{@conn.username}.TEST_TYPE_MAP_METHOD>",
1767
+ },
1768
+ :arguments => [],
1769
+ :inspect => "#<OCI8::Metadata::TypeArgument: SELF #{@conn.username}.TEST_TYPE_MAP_METHOD>",
1770
+ },
1771
+ },
1772
+ :inspect => '#<OCI8::Metadata::TypeMethod: AREA>',
1773
+ },
1774
+ :order_method => nil,
1775
+ }
1776
+ @conn.exec(<<-EOS)
1777
+ CREATE TYPE test_type_order_method AS OBJECT (
1778
+ x integer,
1779
+ y integer,
1780
+ ORDER MEMBER FUNCTION match(l test_type_order_method) RETURN INTEGER
1781
+ )
1782
+ EOS
1783
+ attrs_map['TEST_TYPE_ORDER_METHOD'] = {
1784
+ :class => OCI8::Metadata::Type,
1785
+ :map_method => nil,
1786
+ :order_method => {
1787
+ :class => OCI8::Metadata::TypeMethod,
1788
+ :name => 'MATCH',
1789
+ :encapsulation => :public,
1790
+ :has_result? => true,
1791
+ :is_constructor? => false,
1792
+ :is_destructor? => false,
1793
+ :is_operator? => false,
1794
+ :is_selfish? => true,
1795
+ :is_map? => false,
1796
+ :is_order? => true,
1797
+ :is_rnds? => true,
1798
+ :is_rnps? => true,
1799
+ :is_wnds? => true,
1800
+ :is_wnps? => true,
1801
+ :is_final_method? => false,
1802
+ :is_instantiable_method? => true,
1803
+ :is_overriding_method? => false,
1804
+ :arguments => {
1805
+ :class => Array,
1806
+ :size => 2,
1807
+ [0] => {
1808
+ :class => OCI8::Metadata::TypeArgument,
1809
+ :obj_id => nil,
1810
+ :obj_name => nil,
1811
+ :obj_schema => nil,
1812
+ :name => "SELF",
1813
+ :position => 1,
1814
+ :typecode => :named_type,
1815
+ :data_type => :named_type,
1816
+ #:data_size => 0, # ORA-24328: illegal attribute value
1817
+ #:precision => 0, # ORA-24328: illegal attribute value
1818
+ #:scale => 0, # ORA-24328: illegal attribute value
1819
+ :level => 0,
1820
+ :has_default => 0,
1821
+ :has_default? => false,
1822
+ :iomode => :in,
1823
+ #:radix => 0, # ORA-24328: illegal attribute value
1824
+ :type_name => "TEST_TYPE_ORDER_METHOD",
1825
+ :schema_name => @conn.username,
1826
+ #:sub_name => nil, # ORA-24328: illegal attribute value
1827
+ #:link => nil, # ORA-24328: illegal attribute value
1828
+ :type_metadata => {
1829
+ :class => OCI8::Metadata::Type,
1830
+ :inspect => "#<OCI8::Metadata::Type:(0) #{@conn.username}.TEST_TYPE_ORDER_METHOD>",
1831
+ },
1832
+ :arguments => [],
1833
+ :inspect => "#<OCI8::Metadata::TypeArgument: SELF #{@conn.username}.TEST_TYPE_ORDER_METHOD>",
1834
+ },
1835
+ [1] => {
1836
+ :class => OCI8::Metadata::TypeArgument,
1837
+ :obj_id => nil,
1838
+ :obj_name => nil,
1839
+ :obj_schema => nil,
1840
+ :name => "L",
1841
+ :position => 2,
1842
+ :typecode => :named_type,
1843
+ :data_type => :named_type,
1844
+ #:data_size => 0, # ORA-24328: illegal attribute value
1845
+ #:precision => 0, # ORA-24328: illegal attribute value
1846
+ #:scale => 0, # ORA-24328: illegal attribute value
1847
+ :level => 0,
1848
+ :has_default => 0,
1849
+ :has_default? => false,
1850
+ :iomode => :in,
1851
+ #:radix => 0, # ORA-24328: illegal attribute value
1852
+ :type_name => "TEST_TYPE_ORDER_METHOD",
1853
+ :schema_name => @conn.username,
1854
+ #:sub_name => nil, # ORA-24328: illegal attribute value
1855
+ #:link => nil, # ORA-24328: illegal attribute value
1856
+ :type_metadata => {
1857
+ :class => OCI8::Metadata::Type,
1858
+ :inspect => "#<OCI8::Metadata::Type:(0) #{@conn.username}.TEST_TYPE_ORDER_METHOD>",
1859
+ },
1860
+ :arguments => [],
1861
+ :inspect => "#<OCI8::Metadata::TypeArgument: L #{@conn.username}.TEST_TYPE_ORDER_METHOD>",
1862
+ },
1863
+ },
1864
+ :inspect => '#<OCI8::Metadata::TypeMethod: MATCH>',
1865
+ },
1866
+ }
1867
+
1868
+ attrs_map.each do |name, attrs|
1869
+ [
1870
+ @conn.describe_any(name),
1871
+ @conn.describe_type(name),
1872
+ @conn.describe_schema(@conn.username).objects.detect do |obj|
1873
+ obj.obj_name == name
1874
+ end,
1875
+ ].each do |desc|
1876
+ check_attributes(name, desc, attrs)
1877
+ end
1878
+ end
1879
+
1880
+ drop_type('TEST_TYPE_ORDER_METHOD')
1881
+ drop_type('TEST_TYPE_MAP_METHOD')
1882
+ drop_type('TEST_TYPE_HAS_BFILE')
1883
+ drop_type('TEST_TYPE_HAS_BLOB')
1884
+ drop_type('TEST_TYPE_HAS_NCLOB')
1885
+ drop_type('TEST_TYPE_HAS_CLOB')
1886
+ drop_type('TEST_TYPE_INCOMPLETE')
1887
+ drop_type('TEST_TYPE_GRANDCHILD')
1888
+ drop_type('TEST_TYPE_VARRAY')
1889
+ drop_type('TEST_TYPE_NESTEAD_TABLE')
1890
+ drop_type('TEST_TYPE_CHILD')
1891
+ drop_type('TEST_TYPE_PARENT')
1892
+ end # test_type_metadata
1893
+
1894
+ def test_column_metadata
1895
+
1896
+ # Get data_size of NCHAR(1) and that of CHAR(1 CHAR).
1897
+ # They depend on the database character set and the
1898
+ # client character set.
1899
+ @conn.exec('CREATE TABLE test_table (nc NCHAR(1), c CHAR(1 CHAR))')
1900
+ cursor = @conn.exec("select * from test_table")
1901
+ cfrm = cursor.column_metadata[0].data_size # size of NCHAR(1) in bytes
1902
+ csem = cursor.column_metadata[1].data_size # size of CHAR(1 CHAR) in bytes
1903
+ cursor.close
1904
+ drop_table('test_table')
1905
+
1906
+ column_attrs_list = []
1907
+
1908
+ column_attrs_list << {
1909
+ :name => 'CHAR_10_NOT_NULL_COL',
1910
+ :data_type_string => 'CHAR(10) NOT NULL',
1911
+ :data_type => :char,
1912
+ :charset_form => :implicit,
1913
+ :nullable? => false,
1914
+ :char_used? => false,
1915
+ :char_size => 10,
1916
+ :data_size => 10,
1917
+ :precision => 0,
1918
+ :scale => 0,
1919
+ :fsprecision => 0,
1920
+ :lfprecision => 0,
1921
+ :inspect => '#<OCI8::Metadata::Column: CHAR_10_NOT_NULL_COL CHAR(10) NOT NULL>',
1922
+ }
1923
+ column_attrs_list << {
1924
+ :name => 'CHAR_10_CHAR_COL',
1925
+ :data_type_string => 'CHAR(10 CHAR)',
1926
+ :data_type => :char,
1927
+ :charset_form => :implicit,
1928
+ :nullable? => true,
1929
+ :char_used? => true,
1930
+ :char_size => 10,
1931
+ :data_size => 10 * csem,
1932
+ :precision => 0,
1933
+ :scale => 0,
1934
+ :fsprecision => 0,
1935
+ :lfprecision => 0,
1936
+ :inspect => '#<OCI8::Metadata::Column: CHAR_10_CHAR_COL CHAR(10 CHAR)>',
1937
+ }
1938
+ column_attrs_list << {
1939
+ :name => 'NCHAR_10_COL',
1940
+ :data_type_string => 'NCHAR(10)',
1941
+ :data_type => :char,
1942
+ :charset_form => :nchar,
1943
+ :nullable? => true,
1944
+ :char_used? => true,
1945
+ :char_size => 10,
1946
+ :data_size => 10 * cfrm,
1947
+ :precision => 0,
1948
+ :scale => 0,
1949
+ :fsprecision => 0,
1950
+ :lfprecision => 0,
1951
+ :inspect => '#<OCI8::Metadata::Column: NCHAR_10_COL NCHAR(10)>',
1952
+ }
1953
+ column_attrs_list << {
1954
+ :name => 'VARCHAR2_10_COL',
1955
+ :data_type_string => 'VARCHAR2(10)',
1956
+ :data_type => :varchar2,
1957
+ :charset_form => :implicit,
1958
+ :nullable? => true,
1959
+ :char_used? => false,
1960
+ :char_size => 10,
1961
+ :data_size => 10,
1962
+ :precision => 0,
1963
+ :scale => 0,
1964
+ :fsprecision => 0,
1965
+ :lfprecision => 0,
1966
+ :inspect => '#<OCI8::Metadata::Column: VARCHAR2_10_COL VARCHAR2(10)>',
1967
+ }
1968
+ column_attrs_list << {
1969
+ :name => 'VARCHAR2_10_CHAR_COL',
1970
+ :data_type_string => 'VARCHAR2(10 CHAR)',
1971
+ :data_type => :varchar2,
1972
+ :charset_form => :implicit,
1973
+ :nullable? => true,
1974
+ :char_used? => true,
1975
+ :char_size => 10,
1976
+ :data_size => 10 * csem,
1977
+ :precision => 0,
1978
+ :scale => 0,
1979
+ :fsprecision => 0,
1980
+ :lfprecision => 0,
1981
+ :inspect => '#<OCI8::Metadata::Column: VARCHAR2_10_CHAR_COL VARCHAR2(10 CHAR)>',
1982
+ }
1983
+ column_attrs_list << {
1984
+ :name => 'NVARCHAR2_10_COL',
1985
+ :data_type_string => 'NVARCHAR2(10)',
1986
+ :data_type => :varchar2,
1987
+ :charset_form => :nchar,
1988
+ :nullable? => true,
1989
+ :char_used? => true,
1990
+ :char_size => 10,
1991
+ :data_size => 10 * cfrm,
1992
+ :precision => 0,
1993
+ :scale => 0,
1994
+ :fsprecision => 0,
1995
+ :lfprecision => 0,
1996
+ :inspect => '#<OCI8::Metadata::Column: NVARCHAR2_10_COL NVARCHAR2(10)>',
1997
+ }
1998
+ column_attrs_list << {
1999
+ :name => 'RAW_10_COL',
2000
+ :data_type_string => 'RAW(10)',
2001
+ :data_type => :raw,
2002
+ :charset_form => nil,
2003
+ :nullable? => true,
2004
+ :char_used? => false,
2005
+ :char_size => 0,
2006
+ :data_size => 10,
2007
+ :precision => 0,
2008
+ :scale => 0,
2009
+ :fsprecision => 0,
2010
+ :lfprecision => 0,
2011
+ :inspect => '#<OCI8::Metadata::Column: RAW_10_COL RAW(10)>',
2012
+ }
2013
+
2014
+ # Skip tests for data_size of CLOB, NCLOB and BLOB
2015
+ # because their values depend on how they are described.
2016
+ #
2017
+ # Oracle 10g XE 10.2.0.1.0 on Linux:
2018
+ # +----------------+-----------+
2019
+ # | | data_size |
2020
+ # +----------------+-----------+
2021
+ # | implicitly(*1) | 4000 |
2022
+ # | explicitly(*2) | 86 |
2023
+ # +----------------+-----------+
2024
+ #
2025
+ # *1 explicitly described by column definition.
2026
+ # *2 implicitly described by select list.
2027
+ column_attrs_list << {
2028
+ :name => 'CLOB_COL',
2029
+ :data_type_string => 'CLOB',
2030
+ :data_type => :clob,
2031
+ :charset_form => :implicit,
2032
+ :nullable? => true,
2033
+ :char_used? => false,
2034
+ :char_size => 0,
2035
+ :data_size => :skip,
2036
+ :precision => 0,
2037
+ :scale => 0,
2038
+ :fsprecision => 0,
2039
+ :lfprecision => 0,
2040
+ :inspect => '#<OCI8::Metadata::Column: CLOB_COL CLOB>',
2041
+ }
2042
+ column_attrs_list << {
2043
+ :name => 'NCLOB_COL',
2044
+ :data_type_string => 'NCLOB',
2045
+ :data_type => :clob,
2046
+ :charset_form => :nchar,
2047
+ :nullable? => true,
2048
+ :char_used? => false,
2049
+ :char_size => 0,
2050
+ :data_size => :skip,
2051
+ :precision => 0,
2052
+ :scale => 0,
2053
+ :fsprecision => 0,
2054
+ :lfprecision => 0,
2055
+ :inspect => '#<OCI8::Metadata::Column: NCLOB_COL NCLOB>',
2056
+ }
2057
+ column_attrs_list << {
2058
+ :name => 'BLOB_COL',
2059
+ :data_type_string => 'BLOB',
2060
+ :data_type => :blob,
2061
+ :charset_form => nil,
2062
+ :nullable? => true,
2063
+ :char_used? => false,
2064
+ :char_size => 0,
2065
+ :data_size => :skip,
2066
+ :precision => 0,
2067
+ :scale => 0,
2068
+ :fsprecision => 0,
2069
+ :lfprecision => 0,
2070
+ :inspect => '#<OCI8::Metadata::Column: BLOB_COL BLOB>',
2071
+ }
2072
+ column_attrs_list << {
2073
+ :name => 'BFILE_COL',
2074
+ :data_type_string => 'BFILE',
2075
+ :data_type => :bfile,
2076
+ :charset_form => nil,
2077
+ :nullable? => true,
2078
+ :char_used? => false,
2079
+ :char_size => 0,
2080
+ :data_size => 530,
2081
+ :precision => 0,
2082
+ :scale => 0,
2083
+ :fsprecision => 0,
2084
+ :lfprecision => 0,
2085
+ :inspect => '#<OCI8::Metadata::Column: BFILE_COL BFILE>',
2086
+ }
2087
+
2088
+ # Skip tests for fsprecision and lfprecision for NUMBER and FLOAT
2089
+ # because their values depend on how they are described.
2090
+ #
2091
+ # Oracle 10g XE 10.2.0.1.0 on Linux:
2092
+ # +-----------------------------+-------------+-------------+
2093
+ # | | fsprecision | lfprecision |
2094
+ # +----------------+------------+-------------+-------------+
2095
+ # | NUMBER | implicitly | 129 | 0 |
2096
+ # | | explicitly | 0 | 129 |
2097
+ # +----------------+------------+-------------+-------------+
2098
+ # | NUMBER(10) | implicitly | 0 | 10 |
2099
+ # | | explicitly | 10 | 0 |
2100
+ # +----------------+------------+-------------+-------------+
2101
+ # | NUMBER(10,2) | implicitly | 2 | 10 |
2102
+ # | | explicitly | 10 | 2 |
2103
+ # +----------------+------------+-------------+-------------+
2104
+ # | FLOAT | implicitly | 129 | 126 |
2105
+ # | | explicitly | 126 | 129 |
2106
+ # +----------------+------------+-------------+-------------+
2107
+ # | FLOAT(10) | implicitly | 129 | 10 |
2108
+ # | | explicitly | 10 | 129 |
2109
+ # +----------------+------------+-------------+-------------+
2110
+ column_attrs_list << {
2111
+ :name => 'NUMBER_COL',
2112
+ :data_type_string => 'NUMBER',
2113
+ :data_type => :number,
2114
+ :charset_form => nil,
2115
+ :nullable? => true,
2116
+ :char_used? => false,
2117
+ :char_size => 0,
2118
+ :data_size => 22,
2119
+ :precision => 0,
2120
+ :scale => -127,
2121
+ :fsprecision => :skip,
2122
+ :lfprecision => :skip,
2123
+ :inspect => '#<OCI8::Metadata::Column: NUMBER_COL NUMBER>',
2124
+ }
2125
+ column_attrs_list << {
2126
+ :name => 'NUMBER_10_COL',
2127
+ :data_type_string => 'NUMBER(10)',
2128
+ :data_type => :number,
2129
+ :charset_form => nil,
2130
+ :nullable? => true,
2131
+ :char_used? => false,
2132
+ :char_size => 0,
2133
+ :data_size => 22,
2134
+ :precision => 10,
2135
+ :scale => 0,
2136
+ :fsprecision => :skip,
2137
+ :lfprecision => :skip,
2138
+ :inspect => '#<OCI8::Metadata::Column: NUMBER_10_COL NUMBER(10)>',
2139
+ }
2140
+ column_attrs_list << {
2141
+ :name => 'NUMBER_10_2_COL',
2142
+ :data_type_string => 'NUMBER(10,2)',
2143
+ :data_type => :number,
2144
+ :charset_form => nil,
2145
+ :nullable? => true,
2146
+ :char_used? => false,
2147
+ :char_size => 0,
2148
+ :data_size => 22,
2149
+ :precision => 10,
2150
+ :scale => 2,
2151
+ :fsprecision => :skip,
2152
+ :lfprecision => :skip,
2153
+ :inspect => '#<OCI8::Metadata::Column: NUMBER_10_2_COL NUMBER(10,2)>',
2154
+ }
2155
+ column_attrs_list << {
2156
+ :name => 'FLOAT_COL',
2157
+ :data_type_string => 'FLOAT',
2158
+ :data_type => :number,
2159
+ :charset_form => nil,
2160
+ :nullable? => true,
2161
+ :char_used? => false,
2162
+ :char_size => 0,
2163
+ :data_size => 22,
2164
+ :precision => 126,
2165
+ :scale => -127,
2166
+ :fsprecision => :skip,
2167
+ :lfprecision => :skip,
2168
+ :inspect => '#<OCI8::Metadata::Column: FLOAT_COL FLOAT>',
2169
+ }
2170
+ column_attrs_list << {
2171
+ :name => 'FLOAT_10_COL',
2172
+ :data_type_string => 'FLOAT(10)',
2173
+ :data_type => :number,
2174
+ :charset_form => nil,
2175
+ :nullable? => true,
2176
+ :char_used? => false,
2177
+ :char_size => 0,
2178
+ :data_size => 22,
2179
+ :precision => 10,
2180
+ :scale => -127,
2181
+ :fsprecision => :skip,
2182
+ :lfprecision => :skip,
2183
+ :inspect => '#<OCI8::Metadata::Column: FLOAT_10_COL FLOAT(10)>',
2184
+ }
2185
+ if $oracle_version >= OCI8::ORAVER_10_1
2186
+ column_attrs_list << {
2187
+ :name => 'BINARY_FLOAT_COL',
2188
+ :data_type_string => 'BINARY_FLOAT',
2189
+ :data_type => :binary_float,
2190
+ :charset_form => nil,
2191
+ :nullable? => true,
2192
+ :char_used? => false,
2193
+ :char_size => 0,
2194
+ :data_size => 4,
2195
+ :precision => 0,
2196
+ :scale => 0,
2197
+ :fsprecision => 0,
2198
+ :lfprecision => 0,
2199
+ :inspect => '#<OCI8::Metadata::Column: BINARY_FLOAT_COL BINARY_FLOAT>',
2200
+ }
2201
+ column_attrs_list << {
2202
+ :name => 'BINARY_DOUBLE_COL',
2203
+ :data_type_string => 'BINARY_DOUBLE',
2204
+ :data_type => :binary_double,
2205
+ :charset_form => nil,
2206
+ :nullable? => true,
2207
+ :char_used? => false,
2208
+ :char_size => 0,
2209
+ :data_size => 8,
2210
+ :precision => 0,
2211
+ :scale => 0,
2212
+ :fsprecision => 0,
2213
+ :lfprecision => 0,
2214
+ :inspect => '#<OCI8::Metadata::Column: BINARY_DOUBLE_COL BINARY_DOUBLE>',
2215
+ }
2216
+ end
2217
+ column_attrs_list << {
2218
+ :name => 'DATE_COL',
2219
+ :data_type_string => 'DATE',
2220
+ :data_type => :date,
2221
+ :charset_form => nil,
2222
+ :nullable? => true,
2223
+ :char_used? => false,
2224
+ :char_size => 0,
2225
+ :data_size => 7,
2226
+ :precision => 0,
2227
+ :scale => 0,
2228
+ :fsprecision => 0,
2229
+ :lfprecision => 0,
2230
+ :inspect => '#<OCI8::Metadata::Column: DATE_COL DATE>',
2231
+ }
2232
+
2233
+ # Skip tests for precision and lfprecision for TIMESTAMP
2234
+ # because their values depend on how they are described.
2235
+ #
2236
+ # Oracle 10g XE 10.2.0.1.0 on Linux:
2237
+ # +------------------------------------------------+-----------+-------------+
2238
+ # | | precision | lfprecision |
2239
+ # +-----------------------------------+------------+-----------+-------------+
2240
+ # | TIMESTAMP | implicitly | 0 | 0 |
2241
+ # | | explicitly | 6 | 6 |
2242
+ # +-----------------------------------+------------+-----------+-------------+
2243
+ # | TIMESTAMP(9) | implicitly | 0 | 0 |
2244
+ # | | explicitly | 9 | 9 |
2245
+ # +-----------------------------------+------------+-----------+-------------+
2246
+ # | TIMESTAMP WITH TIME ZONE | implicitly | 0 | 0 |
2247
+ # | | explicitly | 6 | 6 |
2248
+ # +-----------------------------------+------------+-----------+-------------+
2249
+ # | TIMESTAMP(9) WITH TIME ZONE | implicitly | 0 | 0 |
2250
+ # | | explicitly | 9 | 9 |
2251
+ # +-----------------------------------+------------+-----------+-------------+
2252
+ # | TIMESTAMP WITH LOCAL TIME ZONE | implicitly | 0 | 0 |
2253
+ # | | explicitly | 6 | 6 |
2254
+ # +-----------------------------------+------------+-----------+-------------+
2255
+ # | TIMESTAMP(9) WITH LOCAL TIME ZONE | implicitly | 0 | 0 |
2256
+ # | | explicitly | 9 | 9 |
2257
+ # +-----------------------------------+------------+-----------+-------------+
2258
+ column_attrs_list << {
2259
+ :name => 'TIMESTAMP_COL',
2260
+ :data_type_string => 'TIMESTAMP',
2261
+ :data_type => :timestamp,
2262
+ :charset_form => nil,
2263
+ :nullable? => true,
2264
+ :char_used? => false,
2265
+ :char_size => 0,
2266
+ :data_size => 11,
2267
+ :precision => :skip,
2268
+ :scale => 6,
2269
+ :fsprecision => 6,
2270
+ :lfprecision => :skip,
2271
+ :inspect => '#<OCI8::Metadata::Column: TIMESTAMP_COL TIMESTAMP>',
2272
+ }
2273
+ column_attrs_list << {
2274
+ :name => 'TIMESTAMP_9_COL',
2275
+ :data_type_string => 'TIMESTAMP(9)',
2276
+ :data_type => :timestamp,
2277
+ :charset_form => nil,
2278
+ :nullable? => true,
2279
+ :char_used? => false,
2280
+ :char_size => 0,
2281
+ :data_size => 11,
2282
+ :precision => :skip,
2283
+ :scale => 9,
2284
+ :fsprecision => 9,
2285
+ :lfprecision => :skip,
2286
+ :inspect => '#<OCI8::Metadata::Column: TIMESTAMP_9_COL TIMESTAMP(9)>',
2287
+ }
2288
+ column_attrs_list << {
2289
+ :name => 'TIMESTAMP_TZ_COL',
2290
+ :data_type_string => 'TIMESTAMP WITH TIME ZONE',
2291
+ :data_type => :timestamp_tz,
2292
+ :charset_form => nil,
2293
+ :nullable? => true,
2294
+ :char_used? => false,
2295
+ :char_size => 0,
2296
+ :data_size => 13,
2297
+ :precision => :skip,
2298
+ :scale => 6,
2299
+ :fsprecision => 6,
2300
+ :lfprecision => :skip,
2301
+ :inspect => '#<OCI8::Metadata::Column: TIMESTAMP_TZ_COL TIMESTAMP WITH TIME ZONE>',
2302
+ }
2303
+ column_attrs_list << {
2304
+ :name => 'TIMESTAMP_9_TZ_COL',
2305
+ :data_type_string => 'TIMESTAMP(9) WITH TIME ZONE',
2306
+ :data_type => :timestamp_tz,
2307
+ :charset_form => nil,
2308
+ :nullable? => true,
2309
+ :char_used? => false,
2310
+ :char_size => 0,
2311
+ :data_size => 13,
2312
+ :precision => :skip,
2313
+ :scale => 9,
2314
+ :fsprecision => 9,
2315
+ :lfprecision => :skip,
2316
+ :inspect => '#<OCI8::Metadata::Column: TIMESTAMP_9_TZ_COL TIMESTAMP(9) WITH TIME ZONE>',
2317
+ }
2318
+ column_attrs_list << {
2319
+ :name => 'TIMESTAMP_LTZ_COL',
2320
+ :data_type_string => 'TIMESTAMP WITH LOCAL TIME ZONE',
2321
+ :data_type => :timestamp_ltz,
2322
+ :charset_form => nil,
2323
+ :nullable? => true,
2324
+ :char_used? => false,
2325
+ :char_size => 0,
2326
+ :data_size => 11,
2327
+ :precision => :skip,
2328
+ :scale => 6,
2329
+ :fsprecision => 6,
2330
+ :lfprecision => :skip,
2331
+ :inspect => '#<OCI8::Metadata::Column: TIMESTAMP_LTZ_COL TIMESTAMP WITH LOCAL TIME ZONE>',
2332
+ }
2333
+ column_attrs_list << {
2334
+ :name => 'TIMESTAMP_9_LTZ_COL',
2335
+ :data_type_string => 'TIMESTAMP(9) WITH LOCAL TIME ZONE',
2336
+ :data_type => :timestamp_ltz,
2337
+ :charset_form => nil,
2338
+ :nullable? => true,
2339
+ :char_used? => false,
2340
+ :char_size => 0,
2341
+ :data_size => 11,
2342
+ :precision => :skip,
2343
+ :scale => 9,
2344
+ :fsprecision => 9,
2345
+ :lfprecision => :skip,
2346
+ :inspect => '#<OCI8::Metadata::Column: TIMESTAMP_9_LTZ_COL TIMESTAMP(9) WITH LOCAL TIME ZONE>',
2347
+ }
2348
+
2349
+ # Skip tsets for scale and fsprecision for INTERVAL YEAR TO MONTH
2350
+ # because their values depend on how they are described.
2351
+ #
2352
+ # Oracle 10g XE 10.2.0.1.0 on Linux:
2353
+ # +-------------------------------------------+-----------+-------------+
2354
+ # | | scale | fsprecision |
2355
+ # +------------------------------+------------+-----------+-------------+
2356
+ # | INTERVAL YEAR TO MONTH | implicitly | 0 | 0 |
2357
+ # | | explicitly | 2 | 2 |
2358
+ # +------------------------------+------------+-----------+-------------+
2359
+ # | INTERVAL YEAR(4) TO MONTH | implicitly | 0 | 0 |
2360
+ # | | explicitly | 4 | 4 |
2361
+ # +------------------------------+------------+-----------+-------------+
2362
+ column_attrs_list << {
2363
+ :name => 'INTERVAL_YM_COL',
2364
+ :data_type_string => 'INTERVAL YEAR TO MONTH',
2365
+ :data_type => :interval_ym,
2366
+ :charset_form => nil,
2367
+ :nullable? => true,
2368
+ :char_used? => false,
2369
+ :char_size => 0,
2370
+ :data_size => 5,
2371
+ :precision => 2,
2372
+ :scale => :skip,
2373
+ :fsprecision => :skip,
2374
+ :lfprecision => 2,
2375
+ :inspect => '#<OCI8::Metadata::Column: INTERVAL_YM_COL INTERVAL YEAR TO MONTH>',
2376
+ }
2377
+ column_attrs_list << {
2378
+ :name => 'INTERVAL_YM_4_COL',
2379
+ :data_type_string => 'INTERVAL YEAR(4) TO MONTH',
2380
+ :data_type => :interval_ym,
2381
+ :charset_form => nil,
2382
+ :nullable? => true,
2383
+ :char_used? => false,
2384
+ :char_size => 0,
2385
+ :data_size => 5,
2386
+ :precision => 4,
2387
+ :scale => :skip,
2388
+ :fsprecision => :skip,
2389
+ :lfprecision => 4,
2390
+ :inspect => '#<OCI8::Metadata::Column: INTERVAL_YM_4_COL INTERVAL YEAR(4) TO MONTH>',
2391
+ }
2392
+
2393
+ # Skip tests for precision and scale for INTERVAL DAY TO SECOND
2394
+ # because their values depend on how they are described.
2395
+ #
2396
+ # Oracle 10g XE 10.2.0.1.0 on Linux:
2397
+ # +-------------------------------------------+-----------+-----------+
2398
+ # | | precision | scale |
2399
+ # +------------------------------+------------+-----------+-----------+
2400
+ # | INTERVAL DAY TO SECOND | implicitly | 2 | 6 |
2401
+ # | | explicitly | 6 | 2 |
2402
+ # +------------------------------+------------+-----------+-----------+
2403
+ # | INTERVAL DAY(4) TO SECOND(9) | implicitly | 4 | 9 |
2404
+ # | | explicitly | 9 | 4 |
2405
+ # +------------------------------+------------+-----------+-----------+
2406
+ column_attrs_list << {
2407
+ :name => 'INTERVAL_DS_COL',
2408
+ :data_type_string => 'INTERVAL DAY TO SECOND',
2409
+ :data_type => :interval_ds,
2410
+ :charset_form => nil,
2411
+ :nullable? => true,
2412
+ :char_used? => false,
2413
+ :char_size => 0,
2414
+ :data_size => 11,
2415
+ :precision => :skip,
2416
+ :scale => :skip,
2417
+ :fsprecision => 6,
2418
+ :lfprecision => 2,
2419
+ :inspect => '#<OCI8::Metadata::Column: INTERVAL_DS_COL INTERVAL DAY TO SECOND>',
2420
+ }
2421
+ column_attrs_list << {
2422
+ :name => 'INTERVAL_DS_4_9_COL',
2423
+ :data_type_string => 'INTERVAL DAY(4) TO SECOND(9)',
2424
+ :data_type => :interval_ds,
2425
+ :charset_form => nil,
2426
+ :nullable? => true,
2427
+ :char_used? => false,
2428
+ :char_size => 0,
2429
+ :data_size => 11,
2430
+ :precision => :skip,
2431
+ :scale => :skip,
2432
+ :fsprecision => 9,
2433
+ :lfprecision => 4,
2434
+ :inspect => '#<OCI8::Metadata::Column: INTERVAL_DS_4_9_COL INTERVAL DAY(4) TO SECOND(9)>',
2435
+ }
2436
+
2437
+ # Object Types
2438
+ if $oracle_version >= OCI8::ORAVER_10_1
2439
+ column_attrs_list << {
2440
+ :name => 'SDO_GEOMETRY_COL',
2441
+ :data_type_string => 'MDSYS.SDO_GEOMETRY',
2442
+ :data_type => :named_type,
2443
+ :charset_form => nil,
2444
+ :nullable? => true,
2445
+ :char_used? => false,
2446
+ :char_size => 0,
2447
+ :data_size => :skip, # 1 when explicitly, 2000 when implicitly.
2448
+ :precision => 0,
2449
+ :scale => 0,
2450
+ :fsprecision => 0,
2451
+ :lfprecision => 0,
2452
+ :inspect => '#<OCI8::Metadata::Column: SDO_GEOMETRY_COL MDSYS.SDO_GEOMETRY>',
2453
+ }
2454
+ end
2455
+
2456
+ drop_table('test_table')
2457
+ sql = <<-EOS
2458
+ CREATE TABLE test_table (#{column_attrs_list.collect do |c| c[:name] + " " + c[:data_type_string]; end.join(',')})
2459
+ STORAGE (
2460
+ INITIAL 100k
2461
+ NEXT 100k
2462
+ MINEXTENTS 1
2463
+ MAXEXTENTS UNLIMITED
2464
+ PCTINCREASE 0)
2465
+ EOS
2466
+ @conn.exec(sql)
2467
+ [
2468
+ @conn.describe_any('test_table').columns,
2469
+ @conn.describe_table('test_table').columns,
2470
+ @conn.describe_schema(@conn.username).objects.detect do |obj|
2471
+ obj.obj_name == 'TEST_TABLE'
2472
+ end.columns,
2473
+ @conn.exec('select * from test_table').column_metadata,
2474
+ ].each do |columns|
2475
+ column_attrs_list.each_with_index do |attrs, idx|
2476
+ check_attributes(attrs[:name], columns[idx], attrs)
2477
+ end
2478
+ end
2479
+ drop_table('test_table')
2480
+ end # test_column_metadata
2481
+
2482
+ def assert_sequence(sequence_name, desc, msg)
2483
+ min, max, incr, cache, order = @conn.select_one(<<EOS, sequence_name)
2484
+ select min_value, max_value, increment_by, cache_size, order_flag
2485
+ from user_sequences
2486
+ where sequence_name = :1
2487
+ EOS
2488
+ currval = @conn.select_one("select cast(#{sequence_name}.currval as integer) from dual")[0]
2489
+
2490
+ attrs = {
2491
+ :class => OCI8::Metadata::Sequence,
2492
+ :obj_id => to_obj_id(@conn.username, sequence_name),
2493
+ :obj_name => sequence_name,
2494
+ :obj_schema => @conn.username,
2495
+ :objid => to_obj_id(@conn.username, sequence_name),
2496
+ :min => min.to_i,
2497
+ :max => max.to_i,
2498
+ :incr => incr.to_i,
2499
+ :cache => cache.to_i,
2500
+ :order? => order == 'Y',
2501
+ :hw_mark => Proc.new {|v| currval <= v},
2502
+ :inspect => /#<OCI8::Metadata::Sequence:\(\d+\) #{@conn.username}.#{sequence_name}/,
2503
+ }
2504
+ check_attributes(msg, desc, attrs)
2505
+ end
2506
+
2507
+ def test_sequence
2508
+ begin
2509
+ @conn.exec("DROP SEQUENCE TEST_SEQ_OCI8")
2510
+ rescue OCIError
2511
+ raise if $!.code != 2289 # ORA-02289: sequence does not exist
2512
+ end
2513
+ @conn.exec(<<-EOS)
2514
+ CREATE SEQUENCE TEST_SEQ_OCI8
2515
+ INCREMENT BY 2
2516
+ START WITH 998
2517
+ MAXVALUE 1000
2518
+ MINVALUE 10
2519
+ CYCLE
2520
+ CACHE 5
2521
+ ORDER
2522
+ EOS
2523
+ @conn.select_one('select test_seq_oci8.nextval from dual')
2524
+ assert_sequence('TEST_SEQ_OCI8', @conn.describe_any('test_seq_oci8'), "line: #{__LINE__}")
2525
+ @conn.select_one('select test_seq_oci8.nextval from dual')
2526
+ assert_sequence('TEST_SEQ_OCI8', @conn.describe_sequence('test_seq_oci8'), "line: #{__LINE__}")
2527
+ @conn.select_one('select test_seq_oci8.nextval from dual')
2528
+ assert_sequence('TEST_SEQ_OCI8', @conn.describe_schema(@conn.username).objects.detect do |obj|
2529
+ obj.obj_name == 'TEST_SEQ_OCI8'
2530
+ end, "line: #{__LINE__}")
2531
+
2532
+ @conn.exec("DROP SEQUENCE TEST_SEQ_OCI8")
2533
+ @conn.exec(<<-EOS)
2534
+ CREATE SEQUENCE TEST_SEQ_OCI8
2535
+ INCREMENT BY -1
2536
+ NOMAXVALUE
2537
+ NOMINVALUE
2538
+ NOCYCLE
2539
+ NOCACHE
2540
+ NOORDER
2541
+ EOS
2542
+ # @conn.describe_any('test_seq_oci8').min is:
2543
+ # -99999999999999999999999999 on Oracle 10gR2
2544
+ # -999999999999999999999999999 on Oracle 11gR2
2545
+
2546
+ @conn.select_one('select test_seq_oci8.nextval from dual')
2547
+ assert_sequence('TEST_SEQ_OCI8', @conn.describe_any('test_seq_oci8'), "line: #{__LINE__}")
2548
+ @conn.select_one('select test_seq_oci8.nextval from dual')
2549
+ assert_sequence('TEST_SEQ_OCI8', @conn.describe_sequence('test_seq_oci8'), "line: #{__LINE__}")
2550
+ @conn.select_one('select test_seq_oci8.nextval from dual')
2551
+ assert_sequence('TEST_SEQ_OCI8', @conn.describe_schema(@conn.username).objects.detect do |obj|
2552
+ obj.obj_name == 'TEST_SEQ_OCI8'
2553
+ end, "line: #{__LINE__}")
2554
+
2555
+ @conn.exec("DROP SEQUENCE TEST_SEQ_OCI8")
2556
+ end
2557
+
2558
+ def test_synonym_metadata
2559
+ begin
2560
+ @conn.exec("DROP SYNONYM test_synonym")
2561
+ rescue OCIError
2562
+ raise if $!.code != 1434 # ORA-01434: private synonym to be dropped does not exist
2563
+ end
2564
+
2565
+ # private synonym
2566
+ begin
2567
+ [
2568
+ {
2569
+ :synonym_name => 'FOO.BAR@BAZ.QUZ',
2570
+ :attrs => {
2571
+ :class => OCI8::Metadata::Synonym,
2572
+ :obj_id => nil,
2573
+ :obj_name => 'TEST_SYNONYM',
2574
+ :obj_schema => @conn.username,
2575
+ :schema_name => 'FOO',
2576
+ :name => 'BAR',
2577
+ :link => 'BAZ.QUZ',
2578
+ :translated_name => 'FOO.BAR@BAZ.QUZ',
2579
+ :inspect => /#<OCI8::Metadata::Synonym:\(\d+\) #{@conn.username}.TEST_SYNONYM FOR FOO.BAR@BAZ.QUZ>/,
2580
+ },
2581
+ },
2582
+ {
2583
+ :synonym_name => 'BAR@BAZ.QUZ',
2584
+ :attrs => {
2585
+ :class => OCI8::Metadata::Synonym,
2586
+ :obj_id => nil,
2587
+ :obj_name => 'TEST_SYNONYM',
2588
+ :obj_schema => @conn.username,
2589
+ :schema_name => nil,
2590
+ :name => 'BAR',
2591
+ :link => 'BAZ.QUZ',
2592
+ :translated_name => 'BAR@BAZ.QUZ',
2593
+ :inspect => /#<OCI8::Metadata::Synonym:\(\d+\) #{@conn.username}.TEST_SYNONYM FOR BAR@BAZ.QUZ>/,
2594
+ },
2595
+ },
2596
+ {
2597
+ :synonym_name => 'FOO.BAR',
2598
+ :attrs => {
2599
+ :class => OCI8::Metadata::Synonym,
2600
+ :obj_id => nil,
2601
+ :obj_name => 'TEST_SYNONYM',
2602
+ :obj_schema => @conn.username,
2603
+ :schema_name => 'FOO',
2604
+ :name => 'BAR',
2605
+ :link => nil,
2606
+ :translated_name => 'FOO.BAR',
2607
+ :inspect => /#<OCI8::Metadata::Synonym:\(\d+\) #{@conn.username}.TEST_SYNONYM FOR FOO.BAR>/,
2608
+ },
2609
+ },
2610
+ {
2611
+ :synonym_name => 'BAR',
2612
+ :attrs => {
2613
+ :class => OCI8::Metadata::Synonym,
2614
+ :obj_id => nil,
2615
+ :obj_name => 'TEST_SYNONYM',
2616
+ :obj_schema => @conn.username,
2617
+ :schema_name => @conn.username,
2618
+ :name => 'BAR',
2619
+ :link => nil,
2620
+ :translated_name => "#{@conn.username}.BAR",
2621
+ :inspect => /#<OCI8::Metadata::Synonym:\(\d+\) #{@conn.username}.TEST_SYNONYM FOR #{@conn.username}.BAR>/,
2622
+ },
2623
+ },
2624
+ ].each do |test|
2625
+ synonym_name = test[:synonym_name]
2626
+ attrs = test[:attrs]
2627
+ @conn.exec("CREATE SYNONYM test_synonym FOR #{synonym_name}")
2628
+ [
2629
+ @conn.describe_any('test_synonym'),
2630
+ @conn.describe_synonym('Test_Synonym'),
2631
+ @conn.describe_any(@conn.username + '.test_synonym'),
2632
+ @conn.describe_synonym(@conn.username + '.Test_Synonym'),
2633
+ ].each do |desc|
2634
+ attrs[:obj_id] = to_obj_id(@conn.username, 'TEST_SYNONYM')
2635
+ check_attributes("private synonym #{synonym_name}", desc, attrs)
2636
+ end
2637
+ @conn.exec("DROP SYNONYM test_synonym")
2638
+ end
2639
+ rescue OCIError
2640
+ raise "grant create synonym privilege to user #{@conn.username} to pass tests." if $!.code == 1031 # ORA-01031: insufficient privileges
2641
+ raise
2642
+ end
2643
+
2644
+ # public synonym
2645
+ attrs = {
2646
+ :class => OCI8::Metadata::Synonym,
2647
+ :obj_id => to_obj_id('PUBLIC', 'SDO_GEOMETRY'),
2648
+ :obj_name => 'SDO_GEOMETRY',
2649
+ :obj_schema => 'PUBLIC',
2650
+ :schema_name => 'MDSYS',
2651
+ :name => 'SDO_GEOMETRY',
2652
+ :link => nil,
2653
+ :translated_name => 'MDSYS.SDO_GEOMETRY',
2654
+ :inspect => /#<OCI8::Metadata::Synonym:\(\d+\) PUBLIC.SDO_GEOMETRY FOR MDSYS.SDO_GEOMETRY>/,
2655
+ }
2656
+ [
2657
+ @conn.describe_any('sdo_geometry'),
2658
+ @conn.describe_synonym('sdo_geometry'),
2659
+ @conn.describe_any('public.sdo_geometry'),
2660
+ @conn.describe_synonym('PUBLIC.sdo_geometry'),
2661
+ ].each do |desc|
2662
+ check_attributes('public synonym', desc, attrs)
2663
+ end
2664
+
2665
+ end
2666
+
2667
+ def test_access_metadata_after_logoff
2668
+ metadata = @conn.describe_any('MDSYS.SDO_GEOMETRY')
2669
+ @conn.logoff
2670
+ @conn = nil
2671
+ metadata.inspect # This should not cause segmentation fault.
2672
+ end
2673
+
2674
+ end # TestMetadata