Module: PLSQL::TableClassMethods

Included in:
Table
Defined in:
lib/plsql/table.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#find(schema, table) ⇒ Object



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
31
# File 'lib/plsql/table.rb', line 4

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