ruby-oci8 2.1.5.1-x64-mingw32

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