Class: PLSQL::Procedure

Inherits:
Object
  • Object
show all
Extended by:
ProcedureClassMethods
Defined in:
lib/plsql/procedure.rb

Overview

:nodoc:

Constant Summary collapse

PLSQL_COMPOSITE_TYPES =
['PL/SQL RECORD', 'TABLE', 'VARRAY'].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ProcedureClassMethods

find

Constructor Details

#initialize(schema, procedure, package, override_schema_name, object_id) ⇒ Procedure

Returns a new instance of Procedure.



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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/plsql/procedure.rb', line 51

def initialize(schema, procedure, package, override_schema_name, object_id)
  @schema = schema
  @schema_name = override_schema_name || schema.schema_name
  @procedure = procedure.to_s.upcase
  @package = package
  @arguments = {}
  @argument_list = {}
  @out_list = {}
  @return = {}
  @overloaded = false

  # store reference to previous level record or collection metadata
   = {}

  @schema.select_all(
    "SELECT overload, argument_name, position, data_level,
          data_type, in_out, data_length, data_precision, data_scale, char_used,
          type_owner, type_name, type_subname
    FROM all_arguments
    WHERE object_id = :object_id
    AND owner = :owner
    AND object_name = :procedure_name
    AND NVL(package_name,'nil') = :package
    ORDER BY overload, sequence",
    object_id, @schema_name, @procedure, @package ? @package : 'nil'
  ) do |r|

    overload, argument_name, position, data_level,
        data_type, in_out, data_length, data_precision, data_scale, char_used,
        type_owner, type_name, type_subname = r

    @overloaded ||= !overload.nil?
    # if not overloaded then store arguments at key 0
    overload ||= 0
    @arguments[overload] ||= {}
    @return[overload] ||= nil

    raise ArgumentError, "Parameter type definition inside package is not supported, use CREATE TYPE outside package" if type_subname

     = {
      :position => position && position.to_i,
      :data_type => data_type,
      :in_out => in_out,
      :data_length => data_length && data_length.to_i,
      :data_precision => data_precision && data_precision.to_i,
      :data_scale => data_scale && data_scale.to_i,
      :char_used => char_used,
      :type_owner => type_owner,
      :type_name => type_name,
      :type_subname => type_subname,
      :sql_type_name => "#{type_owner}.#{type_name}"
    }
    if composite_type?(data_type)
      case data_type
      when 'PL/SQL RECORD'
        [:fields] = {}
      end
      [data_level] = 
    end

    # if parameter
    if argument_name
      # top level parameter
      if data_level == 0
        @arguments[overload][argument_name.downcase.to_sym] = 
      # or lower level part of composite type
      else
        case [data_level - 1][:data_type]
        when 'PL/SQL RECORD'
          [data_level - 1][:fields][argument_name.downcase.to_sym] = 
        when 'TABLE', 'VARRAY'
          [data_level - 1][:element] = 
        end
      end
    # if function has return value
    elsif argument_name.nil? && data_level == 0 && in_out == 'OUT'
      @return[overload] = 
    end
  end
  # if procedure is without arguments then create default empty argument list for default overload
  @arguments[0] = {} if @arguments.keys.empty?
  
  @overloads = @arguments.keys.sort
  @overloads.each do |overload|
    @argument_list[overload] = @arguments[overload].keys.sort {|k1, k2| @arguments[overload][k1][:position] <=> @arguments[overload][k2][:position]}
    @out_list[overload] = @argument_list[overload].select {|k| @arguments[overload][k][:in_out] =~ /OUT/}
  end
end

Instance Attribute Details

#argument_listObject (readonly)

Returns the value of attribute argument_list.



48
49
50
# File 'lib/plsql/procedure.rb', line 48

def argument_list
  @argument_list
end

#argumentsObject (readonly)

Returns the value of attribute arguments.



48
49
50
# File 'lib/plsql/procedure.rb', line 48

def arguments
  @arguments
end

#out_listObject (readonly)

Returns the value of attribute out_list.



48
49
50
# File 'lib/plsql/procedure.rb', line 48

def out_list
  @out_list
end

#packageObject (readonly)

Returns the value of attribute package.



49
50
51
# File 'lib/plsql/procedure.rb', line 49

def package
  @package
end

#procedureObject (readonly)

Returns the value of attribute procedure.



49
50
51
# File 'lib/plsql/procedure.rb', line 49

def procedure
  @procedure
end

#returnObject (readonly)

Returns the value of attribute return.



48
49
50
# File 'lib/plsql/procedure.rb', line 48

def return
  @return
end

#schemaObject (readonly)

Returns the value of attribute schema.



49
50
51
# File 'lib/plsql/procedure.rb', line 49

def schema
  @schema
end

#schema_nameObject (readonly)

Returns the value of attribute schema_name.



49
50
51
# File 'lib/plsql/procedure.rb', line 49

def schema_name
  @schema_name
end

Instance Method Details

#composite_type?(data_type) ⇒ Boolean

Returns:

  • (Boolean)


141
142
143
# File 'lib/plsql/procedure.rb', line 141

def composite_type?(data_type)
  PLSQL_COMPOSITE_TYPES.include? data_type
end

#exec(*args, &block) ⇒ Object



149
150
151
152
# File 'lib/plsql/procedure.rb', line 149

def exec(*args, &block)
  call = ProcedureCall.new(self, args)
  call.exec(&block)
end

#overloaded?Boolean

Returns:

  • (Boolean)


145
146
147
# File 'lib/plsql/procedure.rb', line 145

def overloaded?
  @overloaded
end