Class: PLSQL::Type

Inherits:
Object
  • Object
show all
Extended by:
TypeClassMethods
Defined in:
lib/plsql/type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TypeClassMethods

find

Constructor Details

#initialize(schema, type, override_schema_name = nil) ⇒ Type

:nodoc:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/plsql/type.rb', line 39

def initialize(schema, type, override_schema_name = nil) #:nodoc:
  @schema = schema
  @schema_name = override_schema_name || schema.schema_name
  @type_name = type.to_s.upcase
  @attributes = {}

  @typecode = @schema.select_first(
    "SELECT typecode FROM all_types
    WHERE owner = :owner
    AND type_name = :type_name",
    @schema_name, @type_name)[0]

  @schema.select_all(
    "SELECT attr_name, attr_no,
          attr_type_name, length, precision, scale,
          attr_type_owner, attr_type_mod,
          (SELECT t.typecode FROM all_types t
          WHERE t.owner = attr_type_owner
          AND t.type_name = attr_type_name) typecode
    FROM all_type_attrs
    WHERE owner = :owner
    AND type_name = :type_name
    ORDER BY attr_no",
    @schema_name, @type_name
  ) do |r|
    attr_name, position,
          data_type, data_length, data_precision, data_scale,
          data_type_owner, data_type_mod, typecode = r
    @attributes[attr_name.downcase.to_sym] = {
      :position => position && position.to_i,
      :data_type => data_type_owner && (typecode == 'COLLECTION' ? 'TABLE' : 'OBJECT' ) || data_type,
      :data_length => data_type_owner ? nil : data_length && data_length.to_i,
      :data_precision => data_precision && data_precision.to_i,
      :data_scale => data_scale && data_scale.to_i,
      :type_owner => data_type_owner,
      :type_name => data_type_owner && data_type,
      :sql_type_name => data_type_owner && "#{data_type_owner}.#{data_type}"
    }
  end
end

Instance Attribute Details

#attributesObject (readonly)

:nodoc:



37
38
39
# File 'lib/plsql/type.rb', line 37

def attributes
  @attributes
end

#schema_nameObject (readonly)

:nodoc:



37
38
39
# File 'lib/plsql/type.rb', line 37

def schema_name
  @schema_name
end

#type_nameObject (readonly)

:nodoc:



37
38
39
# File 'lib/plsql/type.rb', line 37

def type_name
  @type_name
end

#typecodeObject (readonly)

:nodoc:



37
38
39
# File 'lib/plsql/type.rb', line 37

def typecode
  @typecode
end

Instance Method Details

#attribute_namesObject

list of object type attribute names



81
82
83
# File 'lib/plsql/type.rb', line 81

def attribute_names
  @attribute_names ||= @attributes.keys.sort_by{|k| @attributes[k][:position]}
end