Skip to content

Commit

Permalink
Add support for oracle_enhanced adapter. Don't alias tables in Postgr…
Browse files Browse the repository at this point in the history
…eSQL adapter if it's already been aliased.
  • Loading branch information
Steve Halasz authored and aeden committed Aug 25, 2010
1 parent 3246ef2 commit 49a957b
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 22 deletions.
Expand Up @@ -59,9 +59,7 @@ def create_mapping_view(old_name, new_name, options = {})
end

def drop_table_with_cascade(table_name, options = {})
cmd = "DROP TABLE #{quote_table_name(table_name)}"
cmd += " CASCADE" if supports_drop_table_cascade?
execute cmd
execute "DROP TABLE #{quote_table_name(table_name)} CASCADE"
end

# Drop a view.
Expand Down
20 changes: 2 additions & 18 deletions lib/rails_sql_views/connection_adapters/oracleenhanced_adapter.rb
@@ -1,31 +1,16 @@
module RailsSqlViews
module ConnectionAdapters
module OracleEnhancedAdapter
def self.included(base)
base.alias_method_chain :tables, :views_included
end
# Returns true as this adapter supports views.
def supports_views?
true
end

def tables_with_views_included(name = nil)
tables = []
sql = " SELECT TABLE_NAME FROM USER_TABLES
UNION
SELECT VIEW_NAME AS TABLE_NAME FROM USER_VIEWS"
cursor = execute(sql, name)
while row = cursor.fetch
tables << row[0].downcase
end
tables
end

def base_tables(name = nil) #:nodoc:
tables = []
cursor = execute("SELECT TABLE_NAME FROM USER_TABLES", name)
while row = cursor.fetch
tables << row[0].downcase
tables << row[0]
end
tables
end
Expand All @@ -35,14 +20,13 @@ def views(name = nil) #:nodoc:
views = []
cursor = execute("SELECT VIEW_NAME FROM USER_VIEWS", name)
while row = cursor.fetch
views << row[0].downcase
views << row[0]
end
views
end

# Get the view select statement for the specified table.
def view_select_statement(view, name=nil)
view.upcase!
cursor = execute("SELECT TEXT FROM USER_VIEWS WHERE VIEW_NAME = '#{view}'", name)
if row = cursor.fetch
return row[0]
Expand Down
@@ -0,0 +1,72 @@
module RailsSqlViews
module ConnectionAdapters
module OracleEnhancedAdapter
<<<<<<< HEAD
def self.included(base)
base.alias_method_chain :tables, :views_included
end
=======
>>>>>>> Add support for oracle_enhanced adapter. Don't alias tables in PostgreSQL adapter if it's already been aliased.
# Returns true as this adapter supports views.
def supports_views?
true
end

<<<<<<< HEAD
def tables_with_views_included(name = nil)
tables = []
sql = " SELECT TABLE_NAME FROM USER_TABLES
UNION
SELECT VIEW_NAME AS TABLE_NAME FROM USER_VIEWS"
cursor = execute(sql, name)
while row = cursor.fetch
tables << row[0].downcase
end
tables
end

=======
>>>>>>> Add support for oracle_enhanced adapter. Don't alias tables in PostgreSQL adapter if it's already been aliased.
def base_tables(name = nil) #:nodoc:
tables = []
cursor = execute("SELECT TABLE_NAME FROM USER_TABLES", name)
while row = cursor.fetch
<<<<<<< HEAD
tables << row[0].downcase
=======
tables << row[0]
>>>>>>> Add support for oracle_enhanced adapter. Don't alias tables in PostgreSQL adapter if it's already been aliased.
end
tables
end
alias nonview_tables base_tables

def views(name = nil) #:nodoc:
views = []
cursor = execute("SELECT VIEW_NAME FROM USER_VIEWS", name)
while row = cursor.fetch
<<<<<<< HEAD
views << row[0].downcase
=======
views << row[0]
>>>>>>> Add support for oracle_enhanced adapter. Don't alias tables in PostgreSQL adapter if it's already been aliased.
end
views
end

# Get the view select statement for the specified table.
def view_select_statement(view, name=nil)
<<<<<<< HEAD
view.upcase!
=======
>>>>>>> Add support for oracle_enhanced adapter. Don't alias tables in PostgreSQL adapter if it's already been aliased.
cursor = execute("SELECT TEXT FROM USER_VIEWS WHERE VIEW_NAME = '#{view}'", name)
if row = cursor.fetch
return row[0]
else
raise "No view called #{view} found"
end
end
end
end
end
Expand Up @@ -2,7 +2,7 @@ module RailsSqlViews
module ConnectionAdapters
module PostgreSQLAdapter
def self.included(base)
base.alias_method_chain :tables, :views_included
base.alias_method_chain :tables, :views_included unless method_defined?(:tables_with_views_included)
end
# Returns true as this adapter supports views.
def supports_views?
Expand Down

0 comments on commit 49a957b

Please sign in to comment.