Skip to content

Commit

Permalink
table_exists? only checks tables, does not check views
Browse files Browse the repository at this point in the history
  • Loading branch information
yahonda committed Feb 22, 2017
1 parent 4cecc35 commit 75a9a26
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions lib/active_record/connection_adapters/oracle_enhanced_adapter.rb
Expand Up @@ -585,13 +585,27 @@ def data_sources
end

def table_exists?(table_name)
ActiveSupport::Deprecation.warn(<<-MSG.squish)
#table_exists? currently checks both tables and views.
This behavior is deprecated and will be changed with Rails 5.1 to only check tables.
Use #data_source_exists? instead.
MSG

data_source_exists?(table_name)
table_name = table_name.to_s
if table_name.include?("@")
# db link is not table
false
else
db_link = nil
default_owner = current_schema
end
real_name = ActiveRecord::ConnectionAdapters::OracleEnhanced::Quoting.valid_table_name?(table_name) ?
table_name.upcase : table_name
if real_name.include?(".")
table_owner, table_name = real_name.split(".")
else
table_owner, table_name = default_owner, real_name
end
select_values(<<-SQL, "SCHEMA").any?
SELECT owner, table_name
FROM all_tables
WHERE owner = '#{table_owner}'
AND table_name = q'[#{table_name}]'
SQL
end

# Will return true if database object exists (to be able to use also views and synonyms for ActiveRecord models)
Expand Down

0 comments on commit 75a9a26

Please sign in to comment.