Class: OCI8::TDO

Inherits:
Object
  • Object
show all
Extended by:
BindType::Util
Defined in:
lib/oci8/object.rb,
ext/oci8/object.c

Overview

OCI8::TDO is the class for Type Descriptor Object, which describe Oracle’s object type.

An instance of OCI8::TDO is specific to the connection. This means One TDO instance for a connection is not available to another connection.

Defined Under Namespace

Classes: Attr

Constant Summary collapse

@@result_type_to_bindtype =
{
  'FLOAT'                   => Float,
  'INTEGER'                 => Integer,
  'NUMBER'                  => OraNumber,
  'BINARY_FLOAT'            => :binary_float,
  'BINARY_DOUBLE'           => :binary_double,
  'TIMESTAMP'               => :timestamp,
  'TIMESTAMP WITH TZ'       => :timestamp_tz,
  'TIMESTAMP WITH LOCAL TZ' => :timestamp_ltz,
  'INTERVAL YEAR TO MONTH'  => :interval_ym,
  'INTERVAL DAY TO SECOND'  => :interval_ds,
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BindType::Util

default_timezone, default_timezone=

Constructor Details

#initialize(con, metadata, klass) ⇒ TDO

Returns a new instance of TDO.



373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
# File 'lib/oci8/object.rb', line 373

def initialize(con, , klass)
  @ruby_class = klass
  @typename = .schema_name + '.' + .name

  setup(con, )
  con.instance_variable_get(:@id_to_tdo)[.tdo_id] = self
  con.instance_variable_get(:@name_to_tdo)[@typename] = self
  con.instance_variable_get(:@name_to_tdo)[klass.typename] = self
  if .schema_name == con.username
    con.instance_variable_get(:@name_to_tdo)[.name] = self
  end

  case .typecode
  when :named_type
    @is_final_type = .is_final_type?
    initialize_named_type(con, )
  when :named_collection
    @is_final_type = true
    initialize_named_collection(con, )
  end
end

Instance Attribute Details

#alignmentObject (readonly)

Returns the value of attribute alignment.



344
345
346
# File 'lib/oci8/object.rb', line 344

def alignment
  @alignment
end

#attr_gettersObject (readonly)

Returns the value of attribute attr_getters.



348
349
350
# File 'lib/oci8/object.rb', line 348

def attr_getters
  @attr_getters
end

#attr_settersObject (readonly)

Returns the value of attribute attr_setters.



349
350
351
# File 'lib/oci8/object.rb', line 349

def attr_setters
  @attr_setters
end

#attributesObject (readonly)

Returns the value of attribute attributes.



346
347
348
# File 'lib/oci8/object.rb', line 346

def attributes
  @attributes
end

#class_methodsObject (readonly)

mapping between class method’s ids and their return types. :none means a procedure.

  CREATE OR REPLACE TYPE foo AS OBJECT (
    STATIC FUNCTION bar RETURN INTEGER,
    STATIC PROCEDURE baz,
  );
=> {:bar => Integer, :baz => :none}


359
360
361
# File 'lib/oci8/object.rb', line 359

def class_methods
  @class_methods
end

#coll_attrObject (readonly)

Returns the value of attribute coll_attr.



347
348
349
# File 'lib/oci8/object.rb', line 347

def coll_attr
  @coll_attr
end

#ind_sizeObject (readonly)

Returns the value of attribute ind_size.



343
344
345
# File 'lib/oci8/object.rb', line 343

def ind_size
  @ind_size
end

#instance_methodsObject (readonly)

mapping between instance method’s ids and their return types. :none means a procedure.

  CREATE OR REPLACE TYPE foo AS OBJECT (
    MEMBER FUNCTION bar RETURN INTEGER,
    MEMBER PROCEDURE baz,
  );
=> {:bar => Integer, :baz => :none}


367
368
369
# File 'lib/oci8/object.rb', line 367

def instance_methods
  @instance_methods
end

#ruby_classObject (readonly)

a subclass of OCI8::Object::Base



340
341
342
# File 'lib/oci8/object.rb', line 340

def ruby_class
  @ruby_class
end

#typenameObject (readonly)

full-qualified object type name.

e.g.
 MDSYS.SDO_GEOMETRY


337
338
339
# File 'lib/oci8/object.rb', line 337

def typename
  @typename
end

#val_sizeObject (readonly)

Returns the value of attribute val_size.



342
343
344
# File 'lib/oci8/object.rb', line 342

def val_size
  @val_size
end

Class Method Details

.check_metadata(con, metadata) ⇒ Object



479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
# File 'lib/oci8/object.rb', line 479

def self.(con, )
  case .typecode
  when :char, :varchar, :varchar2
    [ATTR_STRING,    nil, SIZE_OF_POINTER, 2, ALIGNMENT_OF_POINTER]
  when :raw
    [ATTR_RAW,       nil, SIZE_OF_POINTER, 2, ALIGNMENT_OF_POINTER]
  when :number, :decimal
    [ATTR_OCINUMBER, nil, SIZE_OF_OCINUMBER, 2, ALIGNMENT_OF_OCINUMBER]
  when :integer, :smallint
    [ATTR_INTEGER,   nil, SIZE_OF_OCINUMBER, 2, ALIGNMENT_OF_OCINUMBER]
  when :real, :double, :float
    [ATTR_FLOAT,     nil, SIZE_OF_OCINUMBER, 2, ALIGNMENT_OF_OCINUMBER]
  when :date
    [ATTR_OCIDATE,   nil, SIZE_OF_OCIDATE, 2, ALIGNMENT_OF_OCIDATE,
     Proc.new do |val| datetime_to_array(val, :date) end, # set_proc
     Proc.new do |val| array_to_time(val, :local) end, # get_proc
    ]
  when :timestamp
    [ATTR_TIMESTAMP, con, SIZE_OF_POINTER, 2, ALIGNMENT_OF_POINTER,
     Proc.new do |val| datetime_to_array(val, :timestamp) end, # set_proc
     Proc.new do |val| array_to_time(val, :local) end, # get_proc
    ]
  when :timestamp_tz
    [ATTR_TIMESTAMP_TZ, con, SIZE_OF_POINTER, 2, ALIGNMENT_OF_POINTER,
     Proc.new do |val| datetime_to_array(val, :timestamp_tz) end, # set_proc
     Proc.new do |val| array_to_time(val, nil) end, # get_proc
    ]
  when :binary_double
    [ATTR_BINARY_DOUBLE, nil, SIZE_OF_DOUBLE, 2, ALIGNMENT_OF_DOUBLE]
  when :binary_float
    [ATTR_BINARY_FLOAT, nil, SIZE_OF_FLOAT, 2, ALIGNMENT_OF_FLOAT]
  when :named_type
    tdo = con.(.)
    [ATTR_NAMED_TYPE, tdo, tdo.val_size, tdo.ind_size, tdo.alignment]
  when :named_collection
    #datatype, typeinfo, = OCI8::TDO.check_metadata(con, metadata.type_metadata.collection_element)
    #[ATTR_NAMED_COLLECTION, [datatype, typeinfo], SIZE_OF_POINTER, 2, ALIGNMENT_OF_POINTER]
    tdo = con.(.)
    [ATTR_NAMED_COLLECTION, tdo, tdo.val_size, tdo.ind_size, tdo.alignment]
  when :clob
    if .charset_form != :nchar
      [ATTR_CLOB, con, SIZE_OF_POINTER, 2, ALIGNMENT_OF_POINTER]
    else
      [ATTR_NCLOB, con, SIZE_OF_POINTER, 2, ALIGNMENT_OF_POINTER]
    end
  when :blob
    [ATTR_BLOB, con, SIZE_OF_POINTER, 2, ALIGNMENT_OF_POINTER]
  when :bfile
    [ATTR_BFILE, con, SIZE_OF_POINTER, 2, ALIGNMENT_OF_POINTER]
  else
    raise "unsupported typecode #{.typecode}"
  end
end

Instance Method Details

#inspectObject



459
460
461
# File 'lib/oci8/object.rb', line 459

def inspect
  "#<#{self.class}:#@typename>"
end

#is_collection?Boolean

Returns:

  • (Boolean)


369
370
371
# File 'lib/oci8/object.rb', line 369

def is_collection?
  @coll_attr ? true : false
end