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,2148 @@
1
+ # oci8.rb -- implements OCI8::Metadata.
2
+ #
3
+ # Copyright (C) 2006-2013 Kubo Takehiro <kubo@jiubao.org>
4
+ #
5
+ # See {'Describing Schema Metadata' in Oracle Call Interface Programmer's Guide}
6
+ # [http://download-west.oracle.com/docs/cd/B19306_01/appdev.102/b14250/oci06des.htm]
7
+
8
+ #
9
+ class OCI8
10
+
11
+ # OCI8 has methods to obtain information about database objects such
12
+ # as tables, views, procedures, functions ans so on. The obtained
13
+ # data are called metadata and retrived as an instance of
14
+ # OCI8::Metadata::Base's subclass.
15
+ #
16
+ # List of methods which return OCI8::Metadata::Base.
17
+ # * {OCI8#describe_any OCI8#describe_any(object_name)}
18
+ # * {OCI8#describe_table OCI8#describe_table(table_name, table_only = false)}
19
+ # * {OCI8#describe_view OCI8#describe_view(view_name)}
20
+ # * {OCI8#describe_procedure OCI8#describe_procedure(procedure_name)}
21
+ # * {OCI8#describe_function OCI8#describe_function(function_name)}
22
+ # * {OCI8#describe_package OCI8#describe_package(package_name)}
23
+ # * {OCI8#describe_type OCI8#describe_type(type_name)}
24
+ # * {OCI8#describe_synonym OCI8#describe_synonym(synonym_name, check_public_also = true)}
25
+ # * {OCI8#describe_sequence OCI8#describe_sequence(sequence_name)}
26
+ # * {OCI8#describe_schema OCI8#describe_schema(schema_name)}
27
+ # * {OCI8#describe_database OCI8#describe_database(database_name)}
28
+ # * {OCI8::Metadata::Type#map_method OCI8::Metadata::Type#map_method}
29
+ # * {OCI8::Metadata::Type#order_method OCI8::Metadata::Type#order_method}
30
+ # * {OCI8::Metadata::Type#collection_element OCI8::Metadata::Type#collection_element}
31
+ #
32
+ # List of methods which return an array of OCI8::Metadata::Base.
33
+ # * {OCI8::Cursor#column_metadata OCI8::Cursor#column_metadata}
34
+ # * {OCI8::Metadata::Database#schemas OCI8::Metadata::Database#schemas}
35
+ # * {OCI8::Metadata::Schema#all_objects OCI8::Metadata::Schema#all_objects}
36
+ # * {OCI8::Metadata::Schema#objects OCI8::Metadata::Schema#objects}
37
+ # * {OCI8::Metadata::Table#columns OCI8::Metadata::Table#columns}
38
+ # * {OCI8::Metadata::Package#subprograms OCI8::Metadata::Package#subprograms}
39
+ # * {OCI8::Metadata::Subprogram#arguments OCI8::Metadata::Procedure#arguments}
40
+ # * {OCI8::Metadata::Subprogram#arguments OCI8::Metadata::Function#arguments}
41
+ # * {OCI8::Metadata::Type#type_attrs OCI8::Metadata::Type#type_attrs}
42
+ # * {OCI8::Metadata::Type#type_methods OCI8::Metadata::Type#type_methods}
43
+ # * {OCI8::Metadata::TypeMethod#arguments OCI8::Metadata::TypeMethod#arguments}
44
+ #
45
+ # Example:
46
+ # conn = OCI8.new('username/passord')
47
+ # table = conn.describe_table('scott.emp')
48
+ # table.columns.each do |col|
49
+ # puts "#{col.name} #{col.data_type_string}"
50
+ # end
51
+ module Metadata
52
+ # Abstract super class of Metadata classes.
53
+ class Base
54
+ # Table 6-1 Attributes Belonging to All Parameters
55
+
56
+ # Returns the number of parameters.
57
+ def num_params
58
+ attr_get_ub2(OCI_ATTR_NUM_PARAMS)
59
+ end
60
+ private :num_params
61
+
62
+ # Returns the object ID which corresponds to the data dictionary
63
+ # view column ALL_OBJECTS.OBJECT_ID.
64
+ #
65
+ # @return [Integer or nil]
66
+ def obj_id
67
+ attr_get_ub4(OCI_ATTR_OBJ_ID, false)
68
+ end
69
+
70
+ # Returns the object name which corresponds to the data dictionary view column ALL_OBJECTS.OBJECT_NAME.
71
+ #
72
+ # @return [String or nil] object name
73
+ def obj_name
74
+ attr_get_string(OCI_ATTR_OBJ_NAME, false)
75
+ end
76
+
77
+ # Returns the schema name which corresponds to the data dictionary view column ALL_OBJECTS.OWNER.
78
+ #
79
+ # @return [String or nil] schema name
80
+ def obj_schema
81
+ attr_get_string(OCI_ATTR_OBJ_SCHEMA, false)
82
+ end
83
+
84
+ # The timestamp of the object
85
+ #-
86
+ # As far as I checked, it is current timestamp, not the object's timestamp. Why?
87
+ #+
88
+ #def timestamp
89
+ # attr_get_oradate(OCI_ATTR_TIMESTAMP)
90
+ #end
91
+
92
+ # Returns the database link name if the object is at the remote host.
93
+ # Note that this is available only when the object is returned by OCI8#describe_* methods.
94
+ #
95
+ # @return [String or nil] database link name
96
+ # @since 2.1.7
97
+ def obj_link
98
+ @obj_link
99
+ end
100
+
101
+ # @private
102
+ def inspect
103
+ "#<#{self.class.name}:(#{obj_id}) #{obj_schema}.#{obj_name}>"
104
+ end
105
+ private
106
+
107
+ def __boolean(idx)
108
+ attr_get_ub1(idx) == 0 ? false : true
109
+ end
110
+ alias __word attr_get_sb4
111
+ def __anydata(idx); raise NotImplementedError; end
112
+
113
+ # Mapping from SQLT values to names
114
+ # @private
115
+ DATA_TYPE_MAP = {}
116
+
117
+ # SQLT_CHR
118
+ DATA_TYPE_MAP[1] = [:varchar2,
119
+ Proc.new do |p|
120
+ if p.charset_form == :nchar
121
+ "NVARCHAR2(#{p.char_size})"
122
+ elsif p.respond_to?(:char_used?) && p.char_used?
123
+ "VARCHAR2(#{p.char_size} CHAR)"
124
+ else
125
+ "VARCHAR2(#{p.data_size})"
126
+ end
127
+ end]
128
+ # SQLT_NUM
129
+ DATA_TYPE_MAP[2] = [:number,
130
+ Proc.new do |p|
131
+ begin
132
+ case p.scale
133
+ when -127
134
+ case p.precision
135
+ when 0
136
+ "NUMBER"
137
+ when 126
138
+ "FLOAT"
139
+ else
140
+ "FLOAT(#{p.precision})"
141
+ end
142
+ when 0
143
+ case p.precision
144
+ when 0
145
+ "NUMBER"
146
+ else
147
+ "NUMBER(#{p.precision})"
148
+ end
149
+ else
150
+ "NUMBER(#{p.precision},#{p.scale})"
151
+ end
152
+ rescue OCIError
153
+ "NUMBER"
154
+ end
155
+ end]
156
+ # SQLT_LNG
157
+ DATA_TYPE_MAP[8] = [:long, "LONG"]
158
+ # SQLT_DAT
159
+ DATA_TYPE_MAP[12] = [:date, "DATE"]
160
+ # SQLT_BIN
161
+ DATA_TYPE_MAP[23] = [:raw,
162
+ Proc.new do |p|
163
+ "RAW(#{p.data_size})"
164
+ end]
165
+ # SQLT_LBI
166
+ DATA_TYPE_MAP[24] = [:long_raw, "LONG RAW"]
167
+ # SQLT_AFC
168
+ DATA_TYPE_MAP[96] = [:char,
169
+ Proc.new do |p|
170
+ if p.charset_form == :nchar
171
+ "NCHAR(#{p.char_size})"
172
+ elsif p.char_used?
173
+ "CHAR(#{p.char_size} CHAR)"
174
+ else
175
+ "CHAR(#{p.data_size})"
176
+ end
177
+ end]
178
+ # SQLT_IBFLOAT
179
+ DATA_TYPE_MAP[100] = [:binary_float, "BINARY_FLOAT"]
180
+ # SQLT_IBDOUBLE
181
+ DATA_TYPE_MAP[101] = [:binary_double, "BINARY_DOUBLE"]
182
+ # SQLT_RDD
183
+ DATA_TYPE_MAP[104] = [:rowid, "ROWID"]
184
+ # SQLT_NTY
185
+ DATA_TYPE_MAP[108] = [:named_type,
186
+ Proc.new do |p|
187
+ "#{p.schema_name}.#{p.type_name}"
188
+ end]
189
+ # SQLT_REF
190
+ DATA_TYPE_MAP[110] = [:ref,
191
+ Proc.new do |p|
192
+ "REF #{p.schema_name}.#{p.type_name}"
193
+ end]
194
+ # SQLT_CLOB
195
+ DATA_TYPE_MAP[112] = [:clob,
196
+ Proc.new do |p|
197
+ if p.charset_form == :nchar
198
+ "NCLOB"
199
+ else
200
+ "CLOB"
201
+ end
202
+ end]
203
+ # SQLT_BLOB
204
+ DATA_TYPE_MAP[113] = [:blob, "BLOB"]
205
+ # SQLT_BFILE
206
+ DATA_TYPE_MAP[114] = [:bfile, "BFILE"]
207
+ # SQLT_RSET
208
+ DATA_TYPE_MAP[116] = [:cursor, "CURSOR"]
209
+ # SQLT_TIMESTAMP
210
+ DATA_TYPE_MAP[187] = [:timestamp,
211
+ Proc.new do |p|
212
+ fsprecision = p.fsprecision
213
+ if fsprecision == 6
214
+ "TIMESTAMP"
215
+ else
216
+ "TIMESTAMP(#{fsprecision})"
217
+ end
218
+ end]
219
+ # SQLT_TIMESTAMP_TZ
220
+ DATA_TYPE_MAP[188] = [:timestamp_tz,
221
+ Proc.new do |p|
222
+ fsprecision = p.fsprecision
223
+ if fsprecision == 6
224
+ "TIMESTAMP WITH TIME ZONE"
225
+ else
226
+ "TIMESTAMP(#{fsprecision}) WITH TIME ZONE"
227
+ end
228
+ end]
229
+ # SQLT_INTERVAL_YM
230
+ DATA_TYPE_MAP[189] = [:interval_ym,
231
+ Proc.new do |p|
232
+ lfprecision = p.lfprecision
233
+ if lfprecision == 2
234
+ "INTERVAL YEAR TO MONTH"
235
+ else
236
+ "INTERVAL YEAR(#{lfprecision}) TO MONTH"
237
+ end
238
+ end]
239
+ # SQLT_INTERVAL_DS
240
+ DATA_TYPE_MAP[190] = [:interval_ds,
241
+ Proc.new do |p|
242
+ lfprecision = p.lfprecision
243
+ fsprecision = p.fsprecision
244
+ if lfprecision == 2 && fsprecision == 6
245
+ "INTERVAL DAY TO SECOND"
246
+ else
247
+ "INTERVAL DAY(#{lfprecision}) TO SECOND(#{fsprecision})"
248
+ end
249
+ end]
250
+ # SQLT_TIMESTAMP_LTZ
251
+ DATA_TYPE_MAP[232] = [:timestamp_ltz,
252
+ Proc.new do |p|
253
+ fsprecision = p.fsprecision
254
+ if fsprecision == 6
255
+ "TIMESTAMP WITH LOCAL TIME ZONE"
256
+ else
257
+ "TIMESTAMP(#{fsprecision}) WITH LOCAL TIME ZONE"
258
+ end
259
+ end]
260
+ DATA_TYPE_MAP[245] = [:record,
261
+ Proc.new do |p|
262
+ "#{p.schema_name}.#{p.type_name}"
263
+ end]
264
+ DATA_TYPE_MAP[252] = [:boolean, "BOOLEAN"]
265
+ DATA_TYPE_MAP[266] = [:pls_integer, "PLS_INTEGER"]
266
+
267
+ def __data_type # :nodoc:
268
+ return @data_type if defined? @data_type
269
+ entry = DATA_TYPE_MAP[attr_get_ub2(OCI_ATTR_DATA_TYPE)]
270
+ type = entry.nil? ? attr_get_ub2(OCI_ATTR_DATA_TYPE) : entry[0]
271
+ type = type.call(self) if type.is_a? Proc
272
+ @data_type = type
273
+ end
274
+
275
+ def __duration # :nodoc:
276
+ case attr_get_ub2(OCI_ATTR_DURATION)
277
+ when OCI_DURATION_SESSION
278
+ :session
279
+ when OCI_DURATION_TRANS
280
+ :transaction
281
+ when OCI_DURATION_NULL
282
+ nil
283
+ end
284
+ end
285
+
286
+ def __charset_form # :nodoc:
287
+ case attr_get_ub1(OCI_ATTR_CHARSET_FORM)
288
+ when 1; :implicit # for CHAR, VARCHAR2, CLOB w/o a specified set
289
+ when 2; :nchar # for NCHAR, NCHAR VARYING, NCLOB
290
+ when 3; :explicit # for CHAR, etc, with "CHARACTER SET ..." syntax
291
+ when 4; :flexible # for PL/SQL "flexible" parameters
292
+ when 5; :lit_null # for typecheck of NULL and empty_clob() lits
293
+ end
294
+ end
295
+
296
+ def __data_type_string # :nodoc:
297
+ entry = DATA_TYPE_MAP[attr_get_ub2(OCI_ATTR_DATA_TYPE)]
298
+ type = entry.nil? ? "unknown(#{attr_get_ub2(OCI_ATTR_DATA_TYPE)})" : entry[1]
299
+ type = type.call(self) if type.is_a? Proc
300
+ if respond_to?(:nullable?) && !nullable?
301
+ type + " NOT NULL"
302
+ else
303
+ type
304
+ end
305
+ end
306
+
307
+ def __typecode(idx) # :nodoc:
308
+ case attr_get_ub2(idx)
309
+ when 110; :ref # OCI_TYPECODE_REF
310
+ when 12; :date # OCI_TYPECODE_DATE
311
+ when 27; :signed8 # OCI_TYPECODE_SIGNED8
312
+ when 28; :signed16 # OCI_TYPECODE_SIGNED16
313
+ when 29; :signed32 # OCI_TYPECODE_SIGNED32
314
+ when 21; :real # OCI_TYPECODE_REAL
315
+ when 22; :double # OCI_TYPECODE_DOUBLE
316
+ when 100; :binary_float # OCI_TYPECODE_BFLOAT
317
+ when 101; :binary_double # OCI_TYPECODE_BDOUBLE
318
+ when 4; :float # OCI_TYPECODE_FLOAT
319
+ when 2; :number # OCI_TYPECODE_NUMBER
320
+ when 7; :decimal # OCI_TYPECODE_DECIMAL
321
+ when 23; :unsigned8 # OCI_TYPECODE_UNSIGNED8
322
+ when 25; :unsigned16 # OCI_TYPECODE_UNSIGNED16
323
+ when 26; :unsigned32 # OCI_TYPECODE_UNSIGNED32
324
+ when 245; :octet # OCI_TYPECODE_OCTET
325
+ when 246; :smallint # OCI_TYPECODE_SMALLINT
326
+ when 3; :integer # OCI_TYPECODE_INTEGER
327
+ when 95; :raw # OCI_TYPECODE_RAW
328
+ when 32; :ptr # OCI_TYPECODE_PTR
329
+ when 9; :varchar2 # OCI_TYPECODE_VARCHAR2
330
+ when 96; :char # OCI_TYPECODE_CHAR
331
+ when 1; :varchar # OCI_TYPECODE_VARCHAR
332
+ when 105; :mlslabel # OCI_TYPECODE_MLSLABEL
333
+ when 247; :varray # OCI_TYPECODE_VARRAY
334
+ when 248; :table # OCI_TYPECODE_TABLE
335
+ when 108; :named_type # OCI_TYPECODE_OBJECT
336
+ when 58; :opaque # OCI_TYPECODE_OPAQUE
337
+ when 122; :named_collection # OCI_TYPECODE_NAMEDCOLLECTION
338
+ when 113; :blob # OCI_TYPECODE_BLOB
339
+ when 114; :bfile # OCI_TYPECODE_BFILE
340
+ when 112; :clob # OCI_TYPECODE_CLOB
341
+ when 115; :cfile # OCI_TYPECODE_CFILE
342
+ when 185; :time # OCI_TYPECODE_TIME
343
+ when 186; :time_tz # OCI_TYPECODE_TIME_TZ
344
+ when 187; :timestamp # OCI_TYPECODE_TIMESTAMP
345
+ when 188; :timestamp_tz # OCI_TYPECODE_TIMESTAMP_TZ
346
+ when 232; :timestamp_ltz # OCI_TYPECODE_TIMESTAMP_LTZ
347
+ when 189; :interval_ym # OCI_TYPECODE_INTERVAL_YM
348
+ when 190; :interval_ds # OCI_TYPECODE_INTERVAL_DS
349
+ when 104; :urowid # OCI_TYPECODE_UROWID
350
+ #when 228; :otmfirst # OCI_TYPECODE_OTMFIRST
351
+ #when 320; :otmlast # OCI_TYPECODE_OTMLAST
352
+ #when 228; :sysfirst # OCI_TYPECODE_SYSFIRST
353
+ #when 235; :syslast # OCI_TYPECODE_SYSLAST
354
+ when 266; :pls_integer # OCI_TYPECODE_PLS_INTEGER
355
+ when 250; :record # OCI_TYPECODE_RECORD
356
+ when 251; :itable # OCI_TYPECODE_ITABLE
357
+ when 252; :boolean # OCI_TYPECODE_BOOLEAN
358
+ end
359
+ end
360
+ end
361
+
362
+ # Information about database objects which cannot be classified
363
+ # into other metadata classes.
364
+ #
365
+ # An instance of this class is returned by:
366
+ # * {OCI8::Metadata::Schema#all_objects OCI8::Metadata::Schema#all_objects}
367
+ class Unknown < Base
368
+ register_ptype OCI_PTYPE_UNK
369
+ end
370
+
371
+ # Information about tables
372
+ #
373
+ # An instance of this class is returned by:
374
+ # * {OCI8#describe_any OCI8#describe_any(name)}
375
+ # * {OCI8#describe_table OCI8#describe_table(name)}
376
+ # * {OCI8::Metadata::Schema#all_objects OCI8::Metadata::Schema#all_objects}
377
+ # * {OCI8::Metadata::Schema#objects OCI8::Metadata::Schema#objects}
378
+ class Table < Base
379
+ register_ptype OCI_PTYPE_TABLE
380
+
381
+ ## Table 6-2 Attributes Belonging to Tables or Views
382
+
383
+ # Returns number of columns
384
+ #
385
+ # @return [Integer]
386
+ def num_cols
387
+ attr_get_ub2(OCI_ATTR_NUM_COLS)
388
+ end
389
+
390
+ # column list
391
+ def list_columns # :nodoc:
392
+ __param(OCI_ATTR_LIST_COLUMNS)
393
+ end
394
+ private :list_columns
395
+
396
+ # Retruns an instance of OCI8::Metadata::Type if the table is an
397
+ # {object table}[http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28371/adobjint.htm#sthref61].
398
+ # Otherwise, +nil+.
399
+ #
400
+ # @return [OCI8::Metadata::Type or nil]
401
+ def type_metadata
402
+ __type_metadata(OCI8::Metadata::Type) if is_typed?
403
+ end
404
+
405
+ # Returns +true+ if the table is a
406
+ # {temporary table}[http://download.oracle.com/docs/cd/B28359_01/server.111/b28318/schema.htm#i16096].
407
+ # Otherwise, +false+.
408
+ def is_temporary?
409
+ attr_get_ub1(OCI_ATTR_IS_TEMPORARY) != 0
410
+ end
411
+
412
+ # Returns +true+ if the table is a object table. Otherwise, +false+.
413
+ def is_typed?
414
+ attr_get_ub1(OCI_ATTR_IS_TYPED) != 0
415
+ end
416
+
417
+ # Retruns +:transaction+ if the table is a
418
+ # {transaction-specific temporary table}[http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_7002.htm#i2189569].
419
+ # +:session+ if it is a
420
+ # {session-specific temporary table}[http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_7002.htm#i2189569].
421
+ # Otherwise, +nil+.
422
+ #
423
+ # @return [:transaction, :session or nil]
424
+ def duration
425
+ __duration
426
+ end
427
+
428
+ ## Table 6-3 Attributes Specific to Tables
429
+
430
+ # Returns a Data Block Address(DBA) of the segment header.
431
+ #
432
+ # The dba is converted to the file number and the block number
433
+ # by DBMS_UTILITY.DATA_BLOCK_ADDRESS_FILE and
434
+ # DBMS_UTILITY.DATA_BLOCK_ADDRESS_BLOCK respectively.
435
+ #
436
+ # @return [Integer]
437
+ def dba
438
+ attr_get_ub4(OCI_ATTR_RDBA)
439
+ end
440
+
441
+ # Returns a tablespace number the table resides in.
442
+ #
443
+ # @return [Integer]
444
+ def tablespace
445
+ __word(OCI_ATTR_TABLESPACE)
446
+ end
447
+
448
+ # Returns +true+ if the table is part of a
449
+ # cluster[http://download.oracle.com/docs/cd/B28359_01/server.111/b28318/schema.htm#CNCPT608].
450
+ # Otherwise, +false+.
451
+ def clustered?
452
+ attr_get_ub1(OCI_ATTR_CLUSTERED) != 0
453
+ end
454
+
455
+ # Returns +true+ if the table is a
456
+ # {partitioned table}[http://download.oracle.com/docs/cd/B28359_01/server.111/b28318/partconc.htm#i449863].
457
+ # Otherwise, +false+.
458
+ def partitioned?
459
+ attr_get_ub1(OCI_ATTR_PARTITIONED) != 0
460
+ end
461
+
462
+ # Returns +true+ if the table is an
463
+ # {index-organized table}[http://download.oracle.com/docs/cd/B28359_01/server.111/b28318/schema.htm#i23877]
464
+ # Otherwise, +false+.
465
+ def index_only?
466
+ attr_get_ub1(OCI_ATTR_INDEX_ONLY) != 0
467
+ end
468
+
469
+ # Returns column information of the table.
470
+ #
471
+ # @return [array of OCI8::Metadata::Column]
472
+ def columns
473
+ @columns ||= list_columns.to_a
474
+ end
475
+ end
476
+
477
+ # Information about views
478
+ #
479
+ # An instance of this class is returned by:
480
+ # * {OCI8#describe_any OCI8#describe_any(name)}
481
+ # * {OCI8#describe_table OCI8#describe_table(name, false)}
482
+ # * {OCI8#describe_view OCI8#describe_view(name)}
483
+ # * {OCI8::Metadata::Schema#all_objects OCI8::Metadata::Schema#all_objects}
484
+ # * {OCI8::Metadata::Schema#objects OCI8::Metadata::Schema#objects}
485
+ class View < Base
486
+ register_ptype OCI_PTYPE_VIEW
487
+
488
+ ## Table 6-2 Attributes Belonging to Tables or Views
489
+
490
+ # Returns number of columns
491
+ #
492
+ # @return [Integer]
493
+ def num_cols
494
+ attr_get_ub2(OCI_ATTR_NUM_COLS)
495
+ end
496
+
497
+ # column list
498
+ def list_columns # :nodoc:
499
+ __param(OCI_ATTR_LIST_COLUMNS)
500
+ end
501
+ private :list_columns
502
+
503
+ # This does't work for view.
504
+ #def type_metadata
505
+ # __type_metadata(OCI8::Metadata::Type)
506
+ #end
507
+
508
+ # This does't work for view.
509
+ #def is_temporary?
510
+ # attr_get_ub1(OCI_ATTR_IS_TEMPORARY) != 0
511
+ #end
512
+
513
+ # This does't work for view.
514
+ #def is_typed?
515
+ # attr_get_ub1(OCI_ATTR_IS_TYPED) != 0
516
+ #end
517
+
518
+ # This does't work for view.
519
+ #def duration
520
+ # __duration
521
+ #end
522
+
523
+ # Returns column information of the view.
524
+ #
525
+ # @return [array of OCI8::Metadata::Column]
526
+ def columns
527
+ @columns ||= list_columns.to_a
528
+ end
529
+ end
530
+
531
+ # Information about PL/SQL subprograms
532
+ #
533
+ # A PL/SQL subprogram is a named PL/SQL block that can be invoked
534
+ # with a set of parameters. A subprogram can be either a procedure
535
+ # or a function.
536
+ #
537
+ # This is the abstract base class of {OCI8::Metadata::Procedure OCI8::Metadata::Procedure} and
538
+ # {OCI8::Metadata::Function OCI8::Metadata::Function}.
539
+ class Subprogram < Base
540
+ ## Table 6-4 Attribute Belonging to Procedures or Functions
541
+
542
+ # Argument list
543
+ def list_arguments # :nodoc:
544
+ __param(OCI_ATTR_LIST_ARGUMENTS)
545
+ end
546
+ private :list_arguments
547
+
548
+ def obj_id # :nodoc:
549
+ super if is_standalone?
550
+ end
551
+
552
+ def obj_name # :nodoc:
553
+ is_standalone? ? super : attr_get_string(OCI_ATTR_NAME)
554
+ end
555
+
556
+ def obj_schema # :nodoc:
557
+ super if is_standalone?
558
+ end
559
+
560
+ # Returns +true+ if the subprogram has
561
+ # {invoker's rights}[http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/subprograms.htm#i18574].
562
+ # Otherwise, +false+.
563
+ def is_invoker_rights?
564
+ attr_get_ub1(OCI_ATTR_IS_INVOKER_RIGHTS) != 0
565
+ end
566
+
567
+ ## Table 6-5 Attributes Specific to Package Subprograms
568
+
569
+ # name of the subprogram
570
+ #
571
+ #def name
572
+ # attr_get_string(OCI_ATTR_NAME)
573
+ #end
574
+ alias name obj_name # :nodoc: for backward compatibility
575
+
576
+ # Returns +nil+ for a standalone stored subprogram,
577
+ # positive integer for an
578
+ # {overloaded packaged subprogram}[http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/subprograms.htm#i12352],
579
+ # otherwise zero.
580
+ #
581
+ # @return [Integer or nil]
582
+ def overload_id
583
+ attr_get_ub2(OCI_ATTR_OVERLOAD_ID) unless is_standalone?
584
+ end
585
+
586
+ # Returns argument information of the subprogram.
587
+ # If it is a function, the first array element is information of its return type.
588
+ #
589
+ # @return [array of OCI8::Metadata::Argument]
590
+ def arguments
591
+ @arguments ||= list_arguments.to_a
592
+ end
593
+
594
+ # Returns +true+ if the subprogram is standalone, +false+
595
+ # if packaged.
596
+ def is_standalone?
597
+ @is_standalone = true unless defined? @is_standalone
598
+ @is_standalone
599
+ end
600
+
601
+ # @private
602
+ def inspect
603
+ "#<#{self.class.name}: #{name}>"
604
+ end
605
+ end
606
+
607
+ # Information about procedures
608
+ #
609
+ # An instance of this class is returned by:
610
+ # * OCI8#describe_any(name)
611
+ # * OCI8#describe_procedure(name)
612
+ # * OCI8::Metadata::Schema#all_objects
613
+ # * OCI8::Metadata::Schema#objects
614
+ # * OCI8::Metadata::Package#subprograms
615
+ #
616
+ # See OCI8::Metadata::Subprogram.
617
+ class Procedure < Subprogram
618
+ register_ptype OCI_PTYPE_PROC
619
+ end
620
+
621
+ # Information about functions
622
+ #
623
+ # An instance of this class is returned by:
624
+ # * OCI8#describe_any(name)
625
+ # * OCI8#describe_function(name)
626
+ # * OCI8::Metadata::Schema#all_objects
627
+ # * OCI8::Metadata::Schema#objects
628
+ # * OCI8::Metadata::Package#subprograms
629
+ #
630
+ # See OCI8::Metadata::Subprogram.
631
+ class Function < Subprogram
632
+ register_ptype OCI_PTYPE_FUNC
633
+ end
634
+
635
+ # Information about packages.
636
+ #
637
+ # An instance of this class is returned by:
638
+ # * OCI8#describe_any(name)
639
+ # * OCI8#describe_package(name)
640
+ # * OCI8::Metadata::Schema#all_objects
641
+ # * OCI8::Metadata::Schema#objects
642
+ class Package < Base
643
+ register_ptype OCI_PTYPE_PKG
644
+
645
+ ## Table 6-6 Attributes Belonging to Packages
646
+
647
+ # subprogram list
648
+ def list_subprograms # :nodoc:
649
+ __param(OCI_ATTR_LIST_SUBPROGRAMS)
650
+ end
651
+ private :list_subprograms
652
+
653
+ # package type list
654
+ def list_types # :nodoc:
655
+ __param(137) # OCI_ATTR_LIST_PKG_TYPES
656
+ end
657
+ private :list_types
658
+
659
+ # Returns +true+ if the package subprograms have
660
+ # {invoker's rights}[http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/subprograms.htm#i18574].
661
+ # Otherwise, +false+.
662
+ def is_invoker_rights?
663
+ attr_get_ub1(OCI_ATTR_IS_INVOKER_RIGHTS) != 0
664
+ end
665
+
666
+ # Returns an array of Function and Procedure defined within the Package.
667
+ #
668
+ # @return [array of OCI8::Metadata::Function and OCI8::Metadata::Procedure]
669
+ def subprograms
670
+ @subprograms ||= list_subprograms.to_a.each do |prog|
671
+ prog.instance_variable_set(:@is_standalone, false)
672
+ end
673
+ end
674
+
675
+ if OCI8.oracle_client_version < ORAVER_12_1
676
+ def types
677
+ raise "This version of the Oracle client does not support PL/SQL package type descriptions."
678
+ end
679
+ else
680
+ # Returns an array of types defined within the Package.
681
+ #
682
+ # @return [array of OCI8::Metadata::Type]
683
+ # @since 2.1.6
684
+ def types
685
+ @types ||= list_types.to_a.each do |type|
686
+ type.instance_variable_set(:@is_standalone, false)
687
+ end
688
+ end
689
+ end
690
+ end
691
+
692
+ # Information about types
693
+ #
694
+ # An instance of this class is returned by:
695
+ # * OCI8#describe_any(name)
696
+ # * OCI8#describe_type(name)
697
+ # * OCI8::Metadata::Schema#all_objects
698
+ # * OCI8::Metadata::Schema#objects
699
+ class Type < Base
700
+ register_ptype OCI_PTYPE_TYPE
701
+
702
+ ## Table 6-7 Attributes Belonging to Types
703
+
704
+ # to type metadata if possible
705
+ def type_metadata
706
+ self
707
+ end
708
+
709
+ # Returns +:named_type+ if the type is an object type,
710
+ # +:named_collection+ if it is a nested table or a varray.
711
+ #
712
+ # @return [:named_type or :named_collection]
713
+ def typecode
714
+ __typecode(OCI_ATTR_TYPECODE)
715
+ end
716
+
717
+ # Returns +:table+ if the type is a nested table,
718
+ # +:varray+ if it is a varray. Otherwise, +nil+.
719
+ #
720
+ # @return [:table, :varray or nil]
721
+ def collection_typecode
722
+ __typecode(OCI_ATTR_COLLECTION_TYPECODE) if typecode == :named_collection
723
+ end
724
+
725
+ # Returns +true+ if the type is an
726
+ # {incomplete type}[http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28371/adobjmng.htm#i1003083],
727
+ # which is used for {forward declaration}[http://en.wikipedia.org/wiki/Forward_declaration].
728
+ # Otherwise, +false+.
729
+ def is_incomplete_type?
730
+ attr_get_ub1(OCI_ATTR_IS_INCOMPLETE_TYPE) != 0
731
+ end
732
+
733
+ # Always returns +false+ because there is no way to create
734
+ # a type metadata object for a system type such as +NUMBER+,
735
+ # +CHAR+ and +VARCHAR+.
736
+ def is_system_type? # :nodoc:
737
+ attr_get_ub1(OCI_ATTR_IS_SYSTEM_TYPE) != 0
738
+ end
739
+
740
+ # Always returns +false+.
741
+ #--
742
+ # I don't know the definition of predefined type...
743
+ def is_predefined_type? # :nodoc:
744
+ attr_get_ub1(OCI_ATTR_IS_PREDEFINED_TYPE) != 0
745
+ end
746
+
747
+ # Always returns +false+ because there is no way to create
748
+ # a type metadata object for a transient type, which is a type
749
+ # dynamically created by C API.
750
+ def is_transient_type? # :nodoc:
751
+ attr_get_ub1(OCI_ATTR_IS_TRANSIENT_TYPE) != 0
752
+ end
753
+
754
+ # Always returns +false+.
755
+ #--
756
+ # I don't know the definition of system generated type.
757
+ # What is different with system type and predefined type.
758
+ def is_system_generated_type? # :nodoc:
759
+ attr_get_ub1(OCI_ATTR_IS_SYSTEM_GENERATED_TYPE) != 0
760
+ end
761
+
762
+ # Returns +true+ if the type is a nested table or
763
+ # has a nested table attribute.
764
+ # Otherwise, +false+.
765
+ def has_nested_table?
766
+ attr_get_ub1(OCI_ATTR_HAS_NESTED_TABLE) != 0
767
+ end
768
+
769
+ # Returns +true+ if the type has a CLOB, NCLOB or BLOB
770
+ # attribute.
771
+ # Otherwise, +false+.
772
+ def has_lob?
773
+ attr_get_ub1(OCI_ATTR_HAS_LOB) != 0
774
+ end
775
+
776
+ # Returns +true+ if the type has a BFILE attribute.
777
+ # Otherwise, +false+.
778
+ def has_file?
779
+ attr_get_ub1(OCI_ATTR_HAS_FILE) != 0
780
+ end
781
+
782
+ # Returns element information of the collection type if the type is a nested
783
+ # table or a varray.
784
+ # Otherwise, +nil+.
785
+ #
786
+ # @return [OCI8::Metadata::Collection or nil]
787
+ def collection_element
788
+ __param(OCI_ATTR_COLLECTION_ELEMENT) if typecode == :named_collection
789
+ end
790
+
791
+ # Returns number of type attributes.
792
+ #
793
+ # @return [Integer]
794
+ def num_type_attrs
795
+ attr_get_ub2(OCI_ATTR_NUM_TYPE_ATTRS)
796
+ end
797
+
798
+ # list of type attributes
799
+ def list_type_attrs # :nodoc:
800
+ __param(OCI_ATTR_LIST_TYPE_ATTRS)
801
+ end
802
+ private :list_type_attrs
803
+
804
+ # Returns number of type methods.
805
+ #
806
+ # @return [Integer]
807
+ def num_type_methods
808
+ attr_get_ub2(OCI_ATTR_NUM_TYPE_METHODS)
809
+ end
810
+
811
+ # list of type methods
812
+ def list_type_methods # :nodoc:
813
+ __param(OCI_ATTR_LIST_TYPE_METHODS)
814
+ end
815
+ private :list_type_methods
816
+
817
+ # Returns information of the
818
+ # {map method}[http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28371/adobjbas.htm#sthref180]
819
+ # if it is defined in the type. Otherwise, +nil+.
820
+ #
821
+ # @return [OCI8::Metadata::TypeMethod or nil]
822
+ def map_method
823
+ __param(OCI_ATTR_MAP_METHOD)
824
+ end
825
+
826
+ # Returns information of the
827
+ # {order method}[http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28371/adobjbas.htm#sthref185]
828
+ # if it is defined in the type. Otherwise, +nil+.
829
+ #
830
+ # @return [OCI8::Metadata::TypeMethod or nil]
831
+ def order_method
832
+ __param(OCI_ATTR_ORDER_METHOD)
833
+ end
834
+
835
+ # Returns +true+ if the type has
836
+ # {invoker's rights}[http://download.oracle.com/docs/cd/B28359_01/appdev.111/appdev.111/b28371/adobjdes.htm#ADOBJ00810].
837
+ # Otherwise, +false+.
838
+ def is_invoker_rights?
839
+ attr_get_ub1(OCI_ATTR_IS_INVOKER_RIGHTS) != 0
840
+ end
841
+
842
+ # Returns the type name.
843
+ #
844
+ # @return [String]
845
+ def name
846
+ attr_get_string(OCI_ATTR_NAME)
847
+ end
848
+
849
+ # Returns the schema name where the type has been created.
850
+ #
851
+ # @return [String]
852
+ def schema_name
853
+ attr_get_string(OCI_ATTR_SCHEMA_NAME)
854
+ end
855
+
856
+ # Returns +true+ if the type is a
857
+ # {final type}[http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28371/adobjbas.htm#CIHFBHFC];
858
+ # in other words, subtypes cannot be derived from the type.
859
+ # Otherwise, +false+.
860
+ def is_final_type?
861
+ attr_get_ub1(OCI_ATTR_IS_FINAL_TYPE) != 0
862
+ end
863
+
864
+ # Returns +true+ if the type is not declared without
865
+ # {<tt>NOT INSTANTIABLE</tt>}[http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28371/adobjbas.htm#i456586].
866
+ # Otherwise, +false+.
867
+ def is_instantiable_type?
868
+ attr_get_ub1(OCI_ATTR_IS_INSTANTIABLE_TYPE) != 0
869
+ end
870
+
871
+ # Returns +true+ if the type is a
872
+ # {subtype}[http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28371/adobjbas.htm#BCFJJADG].
873
+ # Otherwise, +false+.
874
+ def is_subtype?
875
+ attr_get_ub1(OCI_ATTR_IS_SUBTYPE) != 0
876
+ end
877
+
878
+ # Returns the supertype's schema name if the type is a subtype.
879
+ # Otherwise, +nil+.
880
+ #
881
+ # @return [String or nil]
882
+ def supertype_schema_name
883
+ attr_get_string(OCI_ATTR_SUPERTYPE_SCHEMA_NAME) if is_subtype?
884
+ end
885
+
886
+ # Returns the supertype's name if the type is a subtype.
887
+ # Otherwise, +nil+.
888
+ #
889
+ # @return [String or nil]
890
+ def supertype_name
891
+ attr_get_string(OCI_ATTR_SUPERTYPE_NAME) if is_subtype?
892
+ end
893
+
894
+ # Returns the package name if the type is a package type.
895
+ # Otherwise, +nil+.
896
+ #
897
+ # @return [String or nil]
898
+ # @since 2.1.6
899
+ def package_name
900
+ attr_get_string(12, false) # OCI_ATTR_PACKAGE_NAME
901
+ end
902
+
903
+ # Returns attribute information of the type.
904
+ #
905
+ # @return [array of OCI8::Metadata::TypeAttr]
906
+ def type_attrs
907
+ @type_attrs ||= list_type_attrs.to_a
908
+ end
909
+
910
+ # Returns method information of the type.
911
+ #
912
+ # @return [array of OCI8::Metadata::TypeMethod]
913
+ def type_methods
914
+ @type_methods ||= list_type_methods.to_a
915
+ end
916
+
917
+ def inspect # :nodoc:
918
+ "#<#{self.class.name}:(#{obj_id}) #{schema_name}.#{name}>"
919
+ end
920
+ end
921
+
922
+ # Metadata for a type attribute.
923
+ #
924
+ # This is returned by:
925
+ # * OCI8::Metadata::Type#type_attrs
926
+ class TypeAttr < Base
927
+ register_ptype OCI_PTYPE_TYPE_ATTR
928
+
929
+ ## Table 6-8 Attributes Belonging to Type Attributes
930
+
931
+ # The maximum size of the type attribute. This length is
932
+ # returned in bytes and not characters for strings and raws. It
933
+ # returns 22 for NUMBERs.
934
+ def data_size
935
+ attr_get_ub2(OCI_ATTR_DATA_SIZE)
936
+ end
937
+
938
+ # typecode
939
+ def typecode
940
+ __typecode(OCI_ATTR_TYPECODE)
941
+ end
942
+
943
+ # the datatype of the type
944
+ def data_type
945
+ __data_type
946
+ end
947
+
948
+ # the type attribute name
949
+ def name
950
+ attr_get_string(OCI_ATTR_NAME)
951
+ end
952
+
953
+ # The precision of numeric type attributes. If the precision is
954
+ # nonzero and scale is -127, then it is a FLOAT, else it is a
955
+ # NUMBER(precision, scale). For the case when precision is 0,
956
+ # NUMBER(precision, scale) can be represented simply as NUMBER.
957
+ def precision
958
+ __is_implicit? ? attr_get_sb2(OCI_ATTR_PRECISION) : attr_get_ub1(OCI_ATTR_PRECISION)
959
+ end
960
+
961
+ # The scale of numeric type attributes. If the precision is
962
+ # nonzero and scale is -127, then it is a FLOAT, else it is a
963
+ # NUMBER(precision, scale). For the case when precision is 0,
964
+ # NUMBER(precision, scale) can be represented simply as NUMBER.
965
+ def scale
966
+ attr_get_sb1(OCI_ATTR_SCALE)
967
+ end
968
+
969
+ # A string which is the type name. The returned value will
970
+ # contain the type name if the datatype is <tt>:named_type</tt>
971
+ # or <tt>:ref</tt>. If the datatype is <tt>:named_type</tt>, the
972
+ # name of the named datatype's type is returned. If the datatype
973
+ # is <tt>:ref</tt>, the type name of the named datatype pointed
974
+ # to by the REF is returned.
975
+ def type_name
976
+ attr_get_string(OCI_ATTR_TYPE_NAME)
977
+ end
978
+
979
+ # schema name where the type has been created.
980
+ def schema_name
981
+ attr_get_string(OCI_ATTR_SCHEMA_NAME)
982
+ end
983
+
984
+ # to type metadata if possible
985
+ def type_metadata
986
+ __type_metadata(OCI8::Metadata::Type)
987
+ end
988
+
989
+ # character set id if the type attribute is of a string/character type.
990
+ def charset_id
991
+ attr_get_ub2(OCI_ATTR_CHARSET_ID)
992
+ end
993
+
994
+ # character set form, if the type attribute is of a string/character type.
995
+ def charset_form
996
+ __charset_form
997
+ end
998
+
999
+ # The fractional seconds precision of a datetime or interval.
1000
+ def fsprecision
1001
+ attr_get_ub1(OCI_ATTR_FSPRECISION)
1002
+ end
1003
+
1004
+ # The leading field precision of an interval
1005
+ def lfprecision
1006
+ attr_get_ub1(OCI_ATTR_LFPRECISION)
1007
+ end
1008
+
1009
+ # character set name if the type attribute is of a string/character type.
1010
+ def charset_name
1011
+ __con.charset_id2name(charset_id)
1012
+ end
1013
+
1014
+ def inspect # :nodoc:
1015
+ "#<#{self.class.name}: #{name} #{__data_type_string}>"
1016
+ end
1017
+ end
1018
+
1019
+ # Metadata for a type method.
1020
+ #
1021
+ # This is returned by:
1022
+ # * OCI8::Metadata::Type#type_methods
1023
+ # * OCI8::Metadata::Type#map_method
1024
+ # * OCI8::Metadata::Type#order_method
1025
+ #
1026
+ #--
1027
+ # How can I know whether FUNCTION or PROCEDURE?
1028
+ #++
1029
+ class TypeMethod < Base
1030
+ register_ptype OCI_PTYPE_TYPE_METHOD
1031
+
1032
+ ## Table 6-9 Attributes Belonging to Type Methods
1033
+
1034
+ # Name of method (procedure or function)
1035
+ def name
1036
+ attr_get_string(OCI_ATTR_NAME)
1037
+ end
1038
+
1039
+ # encapsulation level of the method. Values are <tt>:public</tt>
1040
+ # or <tt>:private</tt>.
1041
+ def encapsulation
1042
+ case attr_get_ub4(OCI_ATTR_ENCAPSULATION)
1043
+ when 0; :private
1044
+ when 1; :public
1045
+ end
1046
+ end
1047
+
1048
+ # argument list
1049
+ def list_arguments
1050
+ __param(OCI_ATTR_LIST_ARGUMENTS)
1051
+ end
1052
+ private :list_arguments
1053
+
1054
+ # indicates method is has rsult
1055
+ def has_result?
1056
+ __boolean(OCI_ATTR_HAS_RESULT)
1057
+ end
1058
+
1059
+ # indicates method is a constructor
1060
+ def is_constructor?
1061
+ __boolean(OCI_ATTR_IS_CONSTRUCTOR)
1062
+ end
1063
+
1064
+ # indicates method is a destructor
1065
+ def is_destructor?
1066
+ __boolean(OCI_ATTR_IS_DESTRUCTOR)
1067
+ end
1068
+
1069
+ # indicates method is an operator
1070
+ def is_operator?
1071
+ __boolean(OCI_ATTR_IS_OPERATOR)
1072
+ end
1073
+
1074
+ # indicates method is selfish
1075
+ def is_selfish?
1076
+ __boolean(OCI_ATTR_IS_SELFISH)
1077
+ end
1078
+
1079
+ # indicates method is a map method
1080
+ def is_map?
1081
+ __boolean(OCI_ATTR_IS_MAP)
1082
+ end
1083
+
1084
+ # Indicates method is an order method
1085
+ def is_order?
1086
+ __boolean(OCI_ATTR_IS_ORDER)
1087
+ end
1088
+
1089
+ # indicates "Read No Data State"(does not query database tables) is set.
1090
+ def is_rnds?
1091
+ __boolean(OCI_ATTR_IS_RNDS)
1092
+ end
1093
+
1094
+ # Indicates "Read No Package State"(does not reference the values of packaged variables) is set.
1095
+ def is_rnps?
1096
+ __boolean(OCI_ATTR_IS_RNPS)
1097
+ end
1098
+
1099
+ # indicates "Write No Data State"(does not modify tables) is set.
1100
+ def is_wnds?
1101
+ __boolean(OCI_ATTR_IS_WNDS)
1102
+ end
1103
+
1104
+ # indicates "Write No Package State"(does not change the values of packaged variables) is set.
1105
+ def is_wnps?
1106
+ __boolean(OCI_ATTR_IS_WNPS)
1107
+ end
1108
+
1109
+ # indicates this is a final method
1110
+ def is_final_method?
1111
+ __boolean(OCI_ATTR_IS_FINAL_METHOD)
1112
+ end
1113
+
1114
+ # indicates this is an instantiable method
1115
+ def is_instantiable_method?
1116
+ __boolean(OCI_ATTR_IS_INSTANTIABLE_METHOD)
1117
+ end
1118
+
1119
+ # indicates this is an overriding method
1120
+ def is_overriding_method?
1121
+ __boolean(OCI_ATTR_IS_OVERRIDING_METHOD)
1122
+ end
1123
+
1124
+ # Returns argument information of the type method.
1125
+ #
1126
+ # The first element is the return type in case of Function.
1127
+ #
1128
+ # @return [array of OCI8::Metadata::Argument]
1129
+ def arguments
1130
+ @arguments ||= list_arguments.to_a
1131
+ end
1132
+
1133
+ def inspect # :nodoc:
1134
+ "#<#{self.class.name}: #{name}>"
1135
+ end
1136
+ end
1137
+
1138
+ # Metadata for a collection.
1139
+ #
1140
+ # This is returned by:
1141
+ # * OCI8::Metadata::Type.collection_element
1142
+ class Collection < Base
1143
+ register_ptype OCI_PTYPE_TYPE_COLL
1144
+
1145
+ ## Table 6-10 Attributes Belonging to Collection Types
1146
+
1147
+ # The maximum size of the type attribute. This length is
1148
+ # returned in bytes and not characters for strings and raws. It
1149
+ # returns 22 for NUMBERs.
1150
+ def data_size
1151
+ attr_get_ub2(OCI_ATTR_DATA_SIZE)
1152
+ end
1153
+
1154
+ # typecode
1155
+ def typecode
1156
+ __typecode(OCI_ATTR_TYPECODE)
1157
+ end
1158
+
1159
+ # the datatype of the type
1160
+ def data_type
1161
+ __data_type
1162
+ end
1163
+
1164
+ # the number of elements in an array. It is only valid for
1165
+ # collections that are arrays.
1166
+ def num_elems
1167
+ attr_get_ub4(OCI_ATTR_NUM_ELEMS)
1168
+ end
1169
+
1170
+ # The precision of numeric type attributes. If the precision is
1171
+ # nonzero and scale is -127, then it is a FLOAT, else it is a
1172
+ # NUMBER(precision, scale). For the case when precision is 0,
1173
+ # NUMBER(precision, scale) can be represented simply as NUMBER.
1174
+ def precision
1175
+ __is_implicit? ? attr_get_sb2(OCI_ATTR_PRECISION) : attr_get_ub1(OCI_ATTR_PRECISION)
1176
+ end
1177
+
1178
+ # The scale of numeric type attributes. If the precision is
1179
+ # nonzero and scale is -127, then it is a FLOAT, else it is a
1180
+ # NUMBER(precision, scale). For the case when precision is 0,
1181
+ # NUMBER(precision, scale) can be represented simply as NUMBER.
1182
+ def scale
1183
+ attr_get_sb1(OCI_ATTR_SCALE)
1184
+ end
1185
+
1186
+ # A string which is the type name. The returned value will
1187
+ # contain the type name if the datatype is <tt>:named_type</tt> or <tt>:ref</tt>.
1188
+ # If the datatype is <tt>:named_type</tt>, the name of the named datatype's
1189
+ # type is returned. If the datatype is <tt>:ref</tt>, the type name
1190
+ # of the named datatype pointed to by the REF is returned.
1191
+ def type_name
1192
+ attr_get_string(OCI_ATTR_TYPE_NAME)
1193
+ end
1194
+
1195
+ # schema name where the type has been created.
1196
+ def schema_name
1197
+ attr_get_string(OCI_ATTR_SCHEMA_NAME)
1198
+ end
1199
+
1200
+ # to type metadata if possible
1201
+ def type_metadata
1202
+ __type_metadata(OCI8::Metadata::Type)
1203
+ end
1204
+
1205
+ # character set id if the type attribute is of a string/character type.
1206
+ def charset_id
1207
+ attr_get_ub2(OCI_ATTR_CHARSET_ID)
1208
+ end
1209
+
1210
+ # character set form, if the type attribute is of a string/character type.
1211
+ def charset_form
1212
+ __charset_form
1213
+ end
1214
+
1215
+ # character set name if the type attribute is of a string/character type.
1216
+ def charset_name
1217
+ __charset_name(charset_id)
1218
+ end
1219
+
1220
+ def inspect # :nodoc:
1221
+ "#<#{self.class.name}: #{__data_type_string}>"
1222
+ end
1223
+ end
1224
+
1225
+ # Metadata for a synonym.
1226
+ #
1227
+ # This is returned by:
1228
+ # * OCI8#describe_any(name)
1229
+ # * OCI8#describe_synonym(name)
1230
+ # * OCI8::Metadata::Schema#all_objects
1231
+ # * OCI8::Metadata::Schema#objects
1232
+ class Synonym < Base
1233
+ register_ptype OCI_PTYPE_SYN
1234
+
1235
+ ## Table 6-11 Attributes Belonging to Synonyms
1236
+
1237
+ # object id
1238
+ def objid
1239
+ @objid ||= attr_get_ub4(OCI_ATTR_OBJID)
1240
+ end
1241
+
1242
+ # schema name of the synonym translation
1243
+ def schema_name
1244
+ @schema_name ||= attr_get_string(OCI_ATTR_SCHEMA_NAME)
1245
+ @schema_name.size == 0 ? nil : @schema_name
1246
+ end
1247
+
1248
+ # object name of the synonym translation
1249
+ def name
1250
+ @name ||= attr_get_string(OCI_ATTR_NAME)
1251
+ end
1252
+
1253
+ # database link name of the synonym translation or nil
1254
+ def link
1255
+ @link ||= attr_get_string(OCI_ATTR_LINK)
1256
+ @link.size == 0 ? nil : @link
1257
+ end
1258
+
1259
+ # full-qualified synonym translation name with schema, object and database link name.
1260
+ def translated_name
1261
+ (schema_name ? schema_name + '.' : '') + name + (link ? '@' + link : '')
1262
+ end
1263
+
1264
+ def inspect # :nodoc:
1265
+ "#<#{self.class.name}:(#{obj_id}) #{obj_schema}.#{obj_name} FOR #{translated_name}>"
1266
+ end
1267
+ end
1268
+
1269
+ # Metadata for a sequence.
1270
+ #
1271
+ # This is returned by:
1272
+ # * OCI8#describe_any(name)
1273
+ # * OCI8#describe_sequence(name)
1274
+ # * OCI8::Metadata::Schema#all_objects
1275
+ # * OCI8::Metadata::Schema#objects
1276
+ class Sequence < Base
1277
+ register_ptype OCI_PTYPE_SEQ
1278
+
1279
+ ## Table 6-12 Attributes Belonging to Sequences
1280
+
1281
+ # object id
1282
+ def objid
1283
+ attr_get_ub4(OCI_ATTR_OBJID)
1284
+ end
1285
+
1286
+ # minimum value
1287
+ #
1288
+ # @return [Integer]
1289
+ def min
1290
+ attr_get_integer(OCI_ATTR_MIN)
1291
+ end
1292
+
1293
+ # maximum value
1294
+ #
1295
+ # @return [Integer]
1296
+ def max
1297
+ attr_get_integer(OCI_ATTR_MAX)
1298
+ end
1299
+
1300
+ # increment
1301
+ #
1302
+ # @return [Integer]
1303
+ def incr
1304
+ attr_get_integer(OCI_ATTR_INCR)
1305
+ end
1306
+
1307
+ # number of sequence numbers cached; zero if the sequence is not a cached sequence.
1308
+ #
1309
+ # @return [Integer]
1310
+ def cache
1311
+ attr_get_integer(OCI_ATTR_CACHE)
1312
+ end
1313
+
1314
+ # whether the sequence is ordered
1315
+ def order?
1316
+ __boolean(OCI_ATTR_ORDER)
1317
+ end
1318
+
1319
+ # high-water mark
1320
+ #
1321
+ # @return [Integer]
1322
+ def hw_mark
1323
+ attr_get_integer(OCI_ATTR_HW_MARK)
1324
+ end
1325
+ end
1326
+
1327
+ # Metadata for a sequence.
1328
+ #
1329
+ # This is returned by:
1330
+ # * OCI8::Metadata::Table#columns
1331
+ class Column < Base
1332
+ register_ptype OCI_PTYPE_COL
1333
+
1334
+ ## Table 6-13 Attributes Belonging to Columns of Tables or Views
1335
+
1336
+ # returns the type of length semantics of the column.
1337
+ # [<tt>:byte</tt>] byte-length semantics
1338
+ # [<tt>:char</tt>] character-length semantics.
1339
+ def char_used?
1340
+ attr_get_ub1(OCI_ATTR_CHAR_USED) != 0
1341
+ end
1342
+
1343
+ # returns the column character length which is the number of
1344
+ # characters allowed in the column. It is the counterpart of
1345
+ # OCI8::Metadata::Column#data_size which gets the byte length.
1346
+ def char_size
1347
+ attr_get_ub2(OCI_ATTR_CHAR_SIZE)
1348
+ end
1349
+
1350
+ # The maximum size of the column. This length is
1351
+ # returned in bytes and not characters for strings and raws.
1352
+ # This returns character length multiplied by NLS ratio for
1353
+ # character-length semantics columns when using Oracle 9i
1354
+ # or upper.
1355
+ def data_size
1356
+ attr_get_ub2(OCI_ATTR_DATA_SIZE)
1357
+ end
1358
+
1359
+ # the datatype of the column.
1360
+ def data_type
1361
+ __data_type
1362
+ end
1363
+
1364
+ # column name
1365
+ def name
1366
+ attr_get_string(OCI_ATTR_NAME)
1367
+ end
1368
+
1369
+ # The precision of numeric columns. If the precision is nonzero
1370
+ # and scale is -127, then it is a FLOAT, else it is a
1371
+ # NUMBER(precision, scale). For the case when precision is 0,
1372
+ # NUMBER(precision, scale) can be represented simply as NUMBER.
1373
+ def precision
1374
+ __is_implicit? ? attr_get_sb2(OCI_ATTR_PRECISION) : attr_get_ub1(OCI_ATTR_PRECISION)
1375
+ end
1376
+
1377
+ # The scale of numeric columns. If the precision is nonzero and
1378
+ # scale is -127, then it is a FLOAT, else it is a
1379
+ # NUMBER(precision, scale). For the case when precision is 0,
1380
+ # NUMBER(precision, scale) can be represented simply as NUMBER.
1381
+ def scale
1382
+ attr_get_sb1(OCI_ATTR_SCALE)
1383
+ end
1384
+
1385
+ # Returns 0 if null values are not permitted for the column
1386
+ def nullable?
1387
+ __boolean(OCI_ATTR_IS_NULL)
1388
+ end
1389
+
1390
+ # Returns a string which is the type name. The returned value
1391
+ # will contain the type name if the datatype is <tt>:named_type</tt> or
1392
+ # <tt>:ref</tt>. If the datatype is <tt>:named_type</tt>, the name of the named
1393
+ # datatype's type is returned. If the datatype is <tt>:ref</tt>, the
1394
+ # type name of the named datatype pointed to by the REF is
1395
+ # returned
1396
+ def type_name
1397
+ rv = attr_get_string(OCI_ATTR_TYPE_NAME)
1398
+ rv.length == 0 ? nil : rv
1399
+ end
1400
+
1401
+ # Returns a string with the schema name under which the type has been created
1402
+ def schema_name
1403
+ rv = attr_get_string(OCI_ATTR_SCHEMA_NAME)
1404
+ rv.length == 0 ? nil : rv
1405
+ end
1406
+
1407
+ # to type metadata if possible
1408
+ def type_metadata
1409
+ case attr_get_ub2(OCI_ATTR_DATA_TYPE)
1410
+ when 108, 110 # named_type or ref
1411
+ __type_metadata(OCI8::Metadata::Type)
1412
+ else
1413
+ nil
1414
+ end
1415
+ end
1416
+
1417
+ # The character set id, if the column is of a string/character type
1418
+ def charset_id
1419
+ attr_get_ub2(OCI_ATTR_CHARSET_ID)
1420
+ end
1421
+
1422
+ # The character set form, if the column is of a string/character type
1423
+ def charset_form
1424
+ __charset_form
1425
+ end
1426
+
1427
+ ## Table 6-8 Attributes Belonging to Type Attributes
1428
+ ## But Column also have these.
1429
+
1430
+ # The fractional seconds precision of a datetime or interval.
1431
+ def fsprecision
1432
+ attr_get_ub1(OCI_ATTR_FSPRECISION)
1433
+ end
1434
+
1435
+ # The leading field precision of an interval
1436
+ def lfprecision
1437
+ attr_get_ub1(OCI_ATTR_LFPRECISION)
1438
+ end
1439
+
1440
+ # The character set name, if the column is of a string/character type
1441
+ def charset_name
1442
+ __charset_name(charset_id)
1443
+ end
1444
+
1445
+ def data_type_string
1446
+ __data_type_string
1447
+ end
1448
+ alias :type_string :data_type_string # :nodoc: old name of data_type_string
1449
+
1450
+ def to_s
1451
+ %Q{"#{name}" #{__data_type_string}}
1452
+ end
1453
+
1454
+ def inspect # :nodoc:
1455
+ "#<#{self.class.name}: #{name} #{__data_type_string}>"
1456
+ end
1457
+ end
1458
+
1459
+ # Abstract super class of Argument, TypeArgument and TypeResult.
1460
+ class ArgBase < Base
1461
+ ## Table 6-14 Attributes Belonging to Arguments/Results
1462
+
1463
+ # the argument name
1464
+ def name
1465
+ attr_get_string(OCI_ATTR_NAME)
1466
+ end
1467
+
1468
+ # the position of the argument in the argument list.
1469
+ def position
1470
+ attr_get_ub2(OCI_ATTR_POSITION)
1471
+ end
1472
+
1473
+ # typecode
1474
+ def typecode
1475
+ __typecode(OCI_ATTR_TYPECODE)
1476
+ end
1477
+
1478
+ # the datatype of the argument
1479
+ def data_type
1480
+ __data_type
1481
+ end
1482
+
1483
+ # The size of the datatype of the argument. This length is
1484
+ # returned in bytes and not characters for strings and raws. It
1485
+ # returns 22 for NUMBERs.
1486
+ def data_size
1487
+ attr_get_ub2(OCI_ATTR_DATA_SIZE)
1488
+ end
1489
+
1490
+ # The precision of numeric arguments. If the precision is
1491
+ # nonzero and scale is -127, then it is a FLOAT, else it is a
1492
+ # NUMBER(precision, scale). For the case when precision is 0,
1493
+ # NUMBER(precision, scale) can be represented simply as NUMBER.
1494
+ def precision
1495
+ __is_implicit? ? attr_get_sb2(OCI_ATTR_PRECISION) : attr_get_ub1(OCI_ATTR_PRECISION)
1496
+ end
1497
+
1498
+ # The scale of numeric arguments. If the precision is nonzero
1499
+ # and scale is -127, then it is a FLOAT, else it is a
1500
+ # NUMBER(precision, scale). For the case when precision is 0,
1501
+ # NUMBER(precision, scale) can be represented simply as NUMBER.
1502
+ def scale
1503
+ attr_get_sb1(OCI_ATTR_SCALE)
1504
+ end
1505
+
1506
+ # The nest level.
1507
+ #
1508
+ # Oracle manual says that it always returns zero. However it returns
1509
+ # the depth of {OCI8::ArgBase#arguments} calls when #arguments returns
1510
+ # a non-empty array.
1511
+ def level
1512
+ attr_get_ub2(OCI_ATTR_LEVEL)
1513
+ end
1514
+
1515
+ # Indicates whether an argument has a default
1516
+ #
1517
+ # @return [1 or 0]
1518
+ # @deprecated
1519
+ def has_default
1520
+ attr_get_ub1(OCI_ATTR_HAS_DEFAULT)
1521
+ end
1522
+
1523
+ # Indicates whether an argument has a default
1524
+ #
1525
+ # @return [true or false]
1526
+ # @since 2.1.6
1527
+ def has_default?
1528
+ __boolean(OCI_ATTR_HAS_DEFAULT)
1529
+ end
1530
+
1531
+ # The list of arguments at the next level (when the argument is
1532
+ # of a record or table type).
1533
+ def list_arguments
1534
+ __param(OCI_ATTR_LIST_ARGUMENTS)
1535
+ end
1536
+ private :list_arguments
1537
+
1538
+ # Indicates the argument mode. Values are <tt>:in</tt>,
1539
+ # <tt>:out</tt> or <tt>:inout</tt>
1540
+ def iomode
1541
+ case attr_get_ub4(OCI_ATTR_IOMODE)
1542
+ when 0; :in
1543
+ when 1; :out
1544
+ when 2; :inout
1545
+ end
1546
+ end
1547
+
1548
+ # Returns a radix (if number type)
1549
+ def radix
1550
+ attr_get_ub1(OCI_ATTR_RADIX)
1551
+ end
1552
+
1553
+ # doesn't work.
1554
+ # def nullable?
1555
+ # __boolean(OCI_ATTR_IS_NULL)
1556
+ # end
1557
+
1558
+ # Returns a string which is the type name, or the package name
1559
+ # in the case of package local types. The returned value will
1560
+ # contain the type name if the datatype is <tt>:named_type</tt> or
1561
+ # <tt>:ref</tt>. If the datatype is <tt>:named_type</tt>, the name of the named
1562
+ # datatype's type is returned. If the datatype is <tt>:ref</tt>, the type
1563
+ # name of the named datatype pointed to by the REF is returned.
1564
+ def type_name
1565
+ attr_get_string(OCI_ATTR_TYPE_NAME)
1566
+ end
1567
+
1568
+ # For <tt>:named_type</tt> or <tt>:ref</tt>, returns a string with the schema name
1569
+ # under which the type was created, or under which the package
1570
+ # was created in the case of package local types
1571
+ def schema_name
1572
+ attr_get_string(OCI_ATTR_SCHEMA_NAME)
1573
+ end
1574
+
1575
+ # For <tt>:named_type</tt> or <tt>:ref</tt>, returns a string with the type name,
1576
+ # in the case of package local types
1577
+ def sub_name
1578
+ attr_get_string(OCI_ATTR_SUB_NAME)
1579
+ end
1580
+
1581
+ # For <tt>:named_type</tt> or <tt>:ref</tt>, returns a string with the database
1582
+ # link name of the database on which the type exists. This can
1583
+ # happen only in the case of package local types, when the
1584
+ # package is remote.
1585
+ def link
1586
+ attr_get_string(OCI_ATTR_LINK)
1587
+ end
1588
+
1589
+ # to type metadata if possible
1590
+ def type_metadata
1591
+ __type_metadata(OCI8::Metadata::Type)
1592
+ end
1593
+
1594
+ # Returns the character set ID if the argument is of a
1595
+ # string/character type
1596
+ def charset_id
1597
+ attr_get_ub2(OCI_ATTR_CHARSET_ID)
1598
+ end
1599
+
1600
+ # Returns the character set form if the argument is of a
1601
+ # string/character type
1602
+ def charset_form
1603
+ __charset_form
1604
+ end
1605
+
1606
+ # Returns the character set name if the argument is of a
1607
+ # string/character type
1608
+ def charset_name
1609
+ __charset_name(charset_id)
1610
+ end
1611
+
1612
+ # The list of arguments at the next level (when the argument is
1613
+ # of a record or table type).
1614
+ #
1615
+ # This method returns an array containing type information when
1616
+ # the type is a user-defined type and the Oracle server version
1617
+ # is 12c or earlier. Otherwise, it returns an empty array.
1618
+ def arguments
1619
+ @arguments ||= list_arguments.to_a
1620
+ end
1621
+
1622
+ def inspect # :nodoc:
1623
+ "#<#{self.class.name}: #{name} #{__data_type_string}>"
1624
+ end
1625
+ end
1626
+
1627
+ # Metadata for a argument.
1628
+ #
1629
+ # This is returned by:
1630
+ # * OCI8::Metadata::Procedure#arguments
1631
+ # * OCI8::Metadata::Function#arguments
1632
+ #
1633
+ # See ArgBase's methods.
1634
+ class Argument < ArgBase
1635
+ register_ptype OCI_PTYPE_ARG
1636
+ end
1637
+
1638
+ # Metadata for a argument.
1639
+ #
1640
+ # This is returned by:
1641
+ # * OCI8::Metadata::TypeMethod#arguments
1642
+ #
1643
+ # See ArgBase's methods.
1644
+ class TypeArgument < ArgBase
1645
+ register_ptype OCI_PTYPE_TYPE_ARG
1646
+ end
1647
+
1648
+ # Metadata for a argument.
1649
+ #
1650
+ # This is returned by: .... unknown.
1651
+ # What's method returns this value?
1652
+ #
1653
+ # See ArgBase's methods.
1654
+ class TypeResult < ArgBase
1655
+ register_ptype OCI_PTYPE_TYPE_RESULT
1656
+ end
1657
+
1658
+ # internal use only.
1659
+ class List < Base # :nodoc:
1660
+ register_ptype OCI_PTYPE_LIST
1661
+
1662
+ ## Table 6-15 List Attributes
1663
+
1664
+ def ltype
1665
+ attr_get_ub2(OCI_ATTR_LTYPE)
1666
+ end
1667
+
1668
+ # convert to array
1669
+ def to_a
1670
+ # Table 6-15 List Attributes
1671
+ case ltype
1672
+ when OCI_LTYPE_COLUMN; offset = 1
1673
+ when OCI_LTYPE_ARG_PROC; offset = 1
1674
+ when OCI_LTYPE_ARG_FUNC; offset = 0
1675
+ when OCI_LTYPE_SUBPRG; offset = 0
1676
+ when OCI_LTYPE_TYPE_ATTR; offset = 1
1677
+ when OCI_LTYPE_TYPE_METHOD; offset = 1
1678
+ when OCI_LTYPE_TYPE_ARG_PROC; offset = 0
1679
+ when OCI_LTYPE_TYPE_ARG_FUNC; offset = 1
1680
+ when OCI_LTYPE_SCH_OBJ; offset = 0
1681
+ when OCI_LTYPE_DB_SCH; offset = 0
1682
+ #when OCI_LTYPE_TYPE_SUBTYPE; offset = ?
1683
+ #when OCI_LTYPE_TABLE_ALIAS; offset = ?
1684
+ #when OCI_LTYPE_VARIABLE_TYPE; offset = ?
1685
+ #when OCI_LTYPE_NAME_VALUE; offset = ?
1686
+ when 15; offset = 0 # OCI_LTYPE_PACKAGE_TYPE
1687
+ else
1688
+ raise NotImplementedError, "unsupported list type #{ltype}"
1689
+ end
1690
+ ary = []
1691
+ 0.upto(num_params - 1) do |i|
1692
+ ary << __param_at(i + offset)
1693
+ end
1694
+ ary
1695
+ end
1696
+ end
1697
+
1698
+ # Metadata for a schema.
1699
+ #
1700
+ # This is returned by:
1701
+ # * OCI8#describe_schema(schema_name)
1702
+ # * OCI8::Metadata::Database#schemas
1703
+ class Schema < Base
1704
+ register_ptype OCI_PTYPE_SCHEMA
1705
+
1706
+ ## Table 6-16 Attributes Specific to Schemas
1707
+
1708
+ def list_objects
1709
+ __param(OCI_ATTR_LIST_OBJECTS)
1710
+ end
1711
+ private :list_objects
1712
+
1713
+ # array of objects in the schema.
1714
+ # This includes unusable objects.
1715
+ def all_objects
1716
+ @all_objects ||=
1717
+ begin
1718
+ begin
1719
+ objs = list_objects
1720
+ rescue OCIError => exc
1721
+ if exc.code != -1
1722
+ raise
1723
+ end
1724
+ # describe again.
1725
+ objs = __con.describe_schema(obj_schema).list_objects
1726
+ end
1727
+ objs.to_a.collect! do |elem|
1728
+ case elem
1729
+ when OCI8::Metadata::Type
1730
+ # to avoid a segmentation fault
1731
+ begin
1732
+ __con.describe_type(elem.obj_schema + '.' + elem.obj_name)
1733
+ rescue OCIError
1734
+ # ignore ORA-24372: invalid object for describe
1735
+ raise if $!.code != 24372
1736
+ end
1737
+ else
1738
+ elem
1739
+ end
1740
+ end.compact
1741
+ end
1742
+ end
1743
+
1744
+ # array of objects in the schema.
1745
+ def objects
1746
+ @objects ||= all_objects.reject do |obj|
1747
+ case obj
1748
+ when Unknown
1749
+ true
1750
+ when Synonym
1751
+ begin
1752
+ obj.objid
1753
+ false
1754
+ rescue OCIError
1755
+ true
1756
+ end
1757
+ else
1758
+ false
1759
+ end
1760
+ end
1761
+ end
1762
+
1763
+ def inspect # :nodoc:
1764
+ "#<#{self.class.name}:(#{obj_id}) #{obj_schema}>"
1765
+ end
1766
+ end
1767
+
1768
+ # Metadata for a database.
1769
+ #
1770
+ # This is returned by:
1771
+ # * OCI8#describe_database(database_name)
1772
+ class Database < Base
1773
+ register_ptype OCI_PTYPE_DATABASE
1774
+
1775
+ # Table 6-17 Attributes Specific to Databases
1776
+
1777
+ # database version
1778
+ def version
1779
+ attr_get_string(OCI_ATTR_VERSION)
1780
+ end
1781
+
1782
+ # database character set Id
1783
+ def charset_id
1784
+ attr_get_ub2(OCI_ATTR_CHARSET_ID)
1785
+ end
1786
+
1787
+ # database national language support character set Id
1788
+ def ncharset_id
1789
+ attr_get_ub2(OCI_ATTR_NCHARSET_ID)
1790
+ end
1791
+
1792
+ # List of schemas in the database
1793
+ def list_schemas
1794
+ __param(OCI_ATTR_LIST_SCHEMAS)
1795
+ end
1796
+ private :list_schemas
1797
+
1798
+ # Maximum length of a procedure name
1799
+ def max_proc_len
1800
+ attr_get_ub4(OCI_ATTR_MAX_PROC_LEN)
1801
+ end
1802
+
1803
+ # Maximum length of a column name
1804
+ def max_column_len
1805
+ attr_get_ub4(OCI_ATTR_MAX_COLUMN_LEN)
1806
+ end
1807
+
1808
+ # How a COMMIT operation affects cursors and prepared statements in
1809
+ # the database. Values are:
1810
+ # [<tt>:cusror_open</tt>] preserve cursor state as before the commit
1811
+ # operation
1812
+ # [<tt>:cursor_closed</tt>] cursors are closed on COMMIT, but the
1813
+ # application can still re-execute the
1814
+ # statement without re-preparing it
1815
+ def cursor_commit_behavior
1816
+ case attr_get_ub1(OCI_ATTR_CURSOR_COMMIT_BEHAVIOR)
1817
+ when 0; :cusror_open
1818
+ when 1; :cursor_closed
1819
+ end
1820
+ end
1821
+
1822
+ # Maximum length of a catalog (database) name
1823
+ def max_catalog_namelen
1824
+ attr_get_ub1(OCI_ATTR_MAX_CATALOG_NAMELEN)
1825
+ end
1826
+
1827
+ # Position of the catalog in a qualified table. Values are
1828
+ # <tt>:cl_start</tt> and <tt>:cl_end</tt>
1829
+ def catalog_location
1830
+ case attr_get_ub1(OCI_ATTR_CATALOG_LOCATION)
1831
+ when 0; :cl_start
1832
+ when 1; :cl_end
1833
+ end
1834
+ end
1835
+
1836
+ # Does database support savepoints? Values are
1837
+ # <tt>:sp_supported</tt> and <tt>:sp_unsupported</tt>
1838
+ def savepoint_support
1839
+ case attr_get_ub1(OCI_ATTR_SAVEPOINT_SUPPORT)
1840
+ when 0; :sp_supported
1841
+ when 1; :sp_unsupported
1842
+ end
1843
+ end
1844
+
1845
+ # Does database support the nowait clause? Values are
1846
+ # <tt>:nw_supported</tt> and <tt>:nw_unsupported</tt>
1847
+ def nowait_support
1848
+ case attr_get_ub1(OCI_ATTR_NOWAIT_SUPPORT)
1849
+ when 0; :nw_supported
1850
+ when 1; :nw_unsupported
1851
+ end
1852
+ end
1853
+
1854
+ # Is autocommit mode required for DDL statements? Values are
1855
+ # <tt>:ac_ddl</tt> and <tt>:no_ac_ddl</tt>
1856
+ def autocommit_ddl
1857
+ case attr_get_ub1(OCI_ATTR_AUTOCOMMIT_DDL)
1858
+ when 0; :ac_ddl
1859
+ when 1; :no_ac_ddl
1860
+ end
1861
+ end
1862
+
1863
+ # Locking mode for the database. Values are <tt>:lock_immediate</tt> and
1864
+ # <tt>:lock_delayed</tt>
1865
+ def locking_mode
1866
+ case attr_get_ub1(OCI_ATTR_LOCKING_MODE)
1867
+ when 0; :lock_immediate
1868
+ when 1; :lock_delayed
1869
+ end
1870
+ end
1871
+
1872
+ # database character set name
1873
+ def charset_name
1874
+ __charset_name(charset_id)
1875
+ end
1876
+
1877
+ # database national language support character set name
1878
+ def ncharset_name
1879
+ __charset_name(ncharset_id)
1880
+ end
1881
+
1882
+ # array of Schema objects in the database
1883
+ def schemas
1884
+ @schemas ||= list_schemas.to_a
1885
+ end
1886
+
1887
+ def inspect # :nodoc:
1888
+ "#<#{self.class.name}:(#{obj_id}) #{obj_name} #{version}>"
1889
+ end
1890
+ end
1891
+
1892
+ =begin
1893
+ class Rule < Base # :nodoc:
1894
+ register_ptype OCI_PTYPE_RULE
1895
+
1896
+ # Table 6-18 Attributes Specific to Rules
1897
+
1898
+ def condition
1899
+ attr_get_string(OCI_ATTR_CONDITION)
1900
+ end
1901
+
1902
+ def eval_context_owner
1903
+ attr_get_string(OCI_ATTR_EVAL_CONTEXT_OWNER)
1904
+ end
1905
+
1906
+ def eval_context_name
1907
+ attr_get_string(OCI_ATTR_EVAL_CONTEXT_NAME)
1908
+ end
1909
+
1910
+ def comment
1911
+ attr_get_string(OCI_ATTR_COMMENT)
1912
+ end
1913
+
1914
+ # def list_action_context
1915
+ # __param(???)
1916
+ # end
1917
+ end
1918
+
1919
+ class RuleSet < Base # :nodoc:
1920
+ register_ptype OCI_PTYPE_RULE_SET
1921
+
1922
+ # Table 6-19 Attributes Specific to Rule Sets
1923
+
1924
+ def eval_context_owner
1925
+ attr_get_string(OCI_ATTR_EVAL_CONTEXT_OWNER)
1926
+ end
1927
+
1928
+ def eval_context_name
1929
+ attr_get_string(OCI_ATTR_EVAL_CONTEXT_NAME)
1930
+ end
1931
+
1932
+ def comment
1933
+ attr_get_string(OCI_ATTR_COMMENT)
1934
+ end
1935
+
1936
+ # def list_rules
1937
+ # __param(???)
1938
+ # end
1939
+ end
1940
+
1941
+ class EvaluationContext < Base # :nodoc:
1942
+ register_ptype OCI_PTYPE_EVALUATION_CONTEXT
1943
+
1944
+ # Table 6-20 Attributes Specific to Evaluation Contexts
1945
+
1946
+ def evaluation_function
1947
+ attr_get_string(OCI_ATTR_EVALUATION_FUNCTION)
1948
+ end
1949
+
1950
+ def comment
1951
+ attr_get_string(OCI_ATTR_COMMENT)
1952
+ end
1953
+
1954
+ def list_table_aliases
1955
+ __param(OCI_ATTR_LIST_TABLE_ALIASES)
1956
+ end
1957
+
1958
+ def list_variable_types
1959
+ __param(OCI_ATTR_LIST_VARIABLE_TYPES)
1960
+ end
1961
+ end
1962
+
1963
+ class TableAlias < Base # :nodoc:
1964
+ register_ptype OCI_PTYPE_TABLE_ALIAS
1965
+
1966
+ # Table 6-21 Attributes Specific to Table Aliases
1967
+
1968
+ def name
1969
+ attr_get_string(OCI_ATTR_NAME)
1970
+ end
1971
+
1972
+ def table_name
1973
+ attr_get_string(OCI_ATTR_TABLE_NAME)
1974
+ end
1975
+ end
1976
+
1977
+ class VariableType < Base # :nodoc:
1978
+ register_ptype OCI_PTYPE_VARIABLE_TYPE
1979
+
1980
+ # Table 6-22 Attributes Specific to Variable Types
1981
+
1982
+ def name
1983
+ attr_get_string(OCI_ATTR_NAME)
1984
+ end
1985
+
1986
+ def var_type
1987
+ attr_get_string(OCI_ATTR_VAR_TYPE)
1988
+ end
1989
+
1990
+ def var_value_function
1991
+ attr_get_string(OCI_ATTR_VAR_VALUE_FUNCTION)
1992
+ end
1993
+
1994
+ def var_method_function
1995
+ attr_get_string(OCI_ATTR_VAR_METHOD_FUNCTION)
1996
+ end
1997
+ end
1998
+
1999
+ class NameValue < Base # :nodoc:
2000
+ register_ptype OCI_PTYPE_NAME_VALUE
2001
+
2002
+ # Table 6-23 Attributes Specific to Name Value Pair
2003
+
2004
+ def name
2005
+ attr_get_string(OCI_ATTR_NAME)
2006
+ end
2007
+
2008
+ # not implemented
2009
+ def value
2010
+ __anydata(OCI_ATTR_VALUE)
2011
+ end
2012
+ end
2013
+ =end
2014
+ end # OCI8::Metadata
2015
+
2016
+ # Returns object information.
2017
+ #
2018
+ # The return type is depends on the object type.
2019
+ #
2020
+ # Oracle type:: Ruby type
2021
+ # Table:: {OCI8::Metadata::Table}
2022
+ # View:: {OCI8::Metadata::View}
2023
+ # Procedure:: {OCI8::Metadata::Procedure}
2024
+ # Function:: {OCI8::Metadata::Function}
2025
+ # Package:: {OCI8::Metadata::Package}
2026
+ # Type:: {OCI8::Metadata::Type}
2027
+ # Synonym:: {OCI8::Metadata::Synonym}
2028
+ # Sequence:: {OCI8::Metadata::Sequence}
2029
+ #
2030
+ # @param [String] object_name
2031
+ # @return [a subclass of OCI8::Metadata::Base]
2032
+ def describe_any(object_name)
2033
+ if /^PUBLIC\.(.*)/i =~ object_name
2034
+ md = __describe($1, OCI8::Metadata::Unknown, true)
2035
+ raise OCIError.new(4043, object_name) if md.obj_schema != 'PUBLIC'
2036
+ md
2037
+ else
2038
+ __describe(object_name, OCI8::Metadata::Unknown, true)
2039
+ end
2040
+ end
2041
+ # Returns table or view information. If the name is a current schema's synonym
2042
+ # name or a public synonym name, it returns table or view information which
2043
+ # the synonym refers.
2044
+ #
2045
+ # If +table_only+ is true, it checks tables in the current schema.
2046
+ #
2047
+ # @param [String] table_name
2048
+ # @param [Boolean] table_only (default: false)
2049
+ # @return [OCI8::Metadata::Table or OCI8::Metadata::View]
2050
+ def describe_table(table_name, table_only = false)
2051
+ if table_only
2052
+ # check my own tables only.
2053
+ __describe(table_name, OCI8::Metadata::Table, false)
2054
+ else
2055
+ # check tables, views, synonyms and public synonyms.
2056
+
2057
+ # follow synonyms up to 20 times to prevent infinite loop
2058
+ # caused by recursive synonyms.
2059
+ recursive_level = 20
2060
+ recursive_level.times do
2061
+ metadata = __describe(table_name, OCI8::Metadata::Unknown, true)
2062
+ case metadata
2063
+ when OCI8::Metadata::Table, OCI8::Metadata::View
2064
+ return metadata
2065
+ when OCI8::Metadata::Synonym
2066
+ table_name = metadata.translated_name
2067
+ if metadata.obj_link and metadata.link.nil?
2068
+ # table_name is a synonym in a remote database for an object in the
2069
+ # remote database itself.
2070
+ table_name = "#{table_name}@#{metadata.obj_link}"
2071
+ end
2072
+ else
2073
+ raise OCIError.new(4043, table_name) # ORA-04043: object %s does not exist
2074
+ end
2075
+ end
2076
+ raise OCIError.new(36, recursive_level) # ORA-00036: maximum number of recursive SQL levels (%s) exceeded
2077
+ end
2078
+ end
2079
+ # Returns view information
2080
+ #
2081
+ # @param [String] view_name
2082
+ # @return [OCI8::Metadata::View]
2083
+ def describe_view(view_name)
2084
+ __describe(view_name, OCI8::Metadata::View, false)
2085
+ end
2086
+ # Returns procedure information
2087
+ #
2088
+ # @param [String] procedure_name
2089
+ # @return [OCI8::Metadata::Procedure]
2090
+ def describe_procedure(procedure_name)
2091
+ __describe(procedure_name, OCI8::Metadata::Procedure, false)
2092
+ end
2093
+ # Returns function information
2094
+ #
2095
+ # @param [String] function_name
2096
+ # @return [OCI8::Metadata::Function]
2097
+ def describe_function(function_name)
2098
+ __describe(function_name, OCI8::Metadata::Function, false)
2099
+ end
2100
+ # Returns package information
2101
+ #
2102
+ # @param [String] package_name
2103
+ # @return [OCI8::Metadata::Package]
2104
+ def describe_package(package_name)
2105
+ __describe(package_name, OCI8::Metadata::Package, false)
2106
+ end
2107
+ # Returns type information
2108
+ #
2109
+ # @param [String] type_name
2110
+ # @return [OCI8::Metadata::Type]
2111
+ def describe_type(type_name)
2112
+ __describe(type_name, OCI8::Metadata::Type, false)
2113
+ end
2114
+ # Returns synonym information
2115
+ #
2116
+ # @param [String] synonym_name
2117
+ # @return [OCI8::Metadata::Synonym]
2118
+ def describe_synonym(synonym_name, check_public_also = true)
2119
+ if /^PUBLIC\.(.*)/i =~ synonym_name
2120
+ md = __describe($1, OCI8::Metadata::Synonym, true)
2121
+ raise OCIError.new(4043, synonym_name) if md.obj_schema != 'PUBLIC'
2122
+ md
2123
+ else
2124
+ __describe(synonym_name, OCI8::Metadata::Synonym, check_public_also)
2125
+ end
2126
+ end
2127
+ # Returns sequence information
2128
+ #
2129
+ # @param [String] sequence_name
2130
+ # @return [OCI8::Metadata::Sequence]
2131
+ def describe_sequence(sequence_name)
2132
+ __describe(sequence_name, OCI8::Metadata::Sequence, false)
2133
+ end
2134
+ # Returns schema information
2135
+ #
2136
+ # @param [String] schema_name
2137
+ # @return [OCI8::Metadata::Schema]
2138
+ def describe_schema(schema_name)
2139
+ __describe(schema_name, OCI8::Metadata::Schema, false)
2140
+ end
2141
+ # Returns database information
2142
+ #
2143
+ # @param [String] database_name
2144
+ # @return [OCI8::Metadata::Database]
2145
+ def describe_database(database_name)
2146
+ __describe(database_name, OCI8::Metadata::Database, false)
2147
+ end
2148
+ end # OCI8