Module: PLSQL::TypeClassMethods

Included in:
Type
Defined in:
lib/plsql/type.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#find(schema, type) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/plsql/type.rb', line 3

def find(schema, type)
  if schema.select_first(
    "SELECT type_name FROM all_types
    WHERE owner = :owner
      AND type_name = :table_name",
        schema.schema_name, type.to_s.upcase)
    new(schema, type)
  # search for synonym
  elsif (row = schema.select_first(
    "SELECT t.owner, t.type_name
    FROM all_synonyms s, all_types t
    WHERE s.owner = :owner
      AND s.synonym_name = :synonym_name
      AND t.owner = s.table_owner
      AND t.type_name = s.table_name
    UNION ALL
    SELECT t.owner, t.type_name
    FROM all_synonyms s, all_types t
    WHERE s.owner = 'PUBLIC'
      AND s.synonym_name = :synonym_name
      AND t.owner = s.table_owner
      AND t.type_name = s.table_name",
        schema.schema_name, type.to_s.upcase, type.to_s.upcase))
    new(schema, row[1], row[0])
  else
    nil
  end
end