From 8f9060ff185b5708edcc8a10a33560c94e535021 Mon Sep 17 00:00:00 2001 From: Anthony Eden Date: Tue, 4 Nov 2008 15:28:57 -0500 Subject: [PATCH] added nonview_tables where missing. need to get tests running again --- CHANGELOG | 3 ++- .../connection_adapters/oci_adapter.rb | 2 +- .../connection_adapters/oracle_adapter.rb | 2 +- .../connection_adapters/postgresql_adapter.rb | 11 +++++++++++ .../connection_adapters/sqlserver_adapter.rb | 6 ++++++ test/README | 1 + 6 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c684153..926314c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -18,4 +18,5 @@ * Updated tests to include new table to support union test 0.7.0 - * Updated dependency versions to get on ActiveRecord 2.x. May not be compatible with Rails versions less than 2.x. \ No newline at end of file + * Updated dependency versions to get on ActiveRecord 2.x. May not be compatible with Rails versions less than 2.x. + * Add nonview_tables support to *all* of the adapters (was missing from Postgres and SQLServer) \ No newline at end of file diff --git a/lib/rails_sql_views/connection_adapters/oci_adapter.rb b/lib/rails_sql_views/connection_adapters/oci_adapter.rb index 375ada8..142d6d3 100644 --- a/lib/rails_sql_views/connection_adapters/oci_adapter.rb +++ b/lib/rails_sql_views/connection_adapters/oci_adapter.rb @@ -6,7 +6,7 @@ def supports_views? true end - def tables(name = nil) #:nodoc: + def nonview_tables(name = nil) #:nodoc: tables = [] execute("SELECT TABLE_NAME FROM USER_TABLES", name).each { |row| tables << row[0] } tables diff --git a/lib/rails_sql_views/connection_adapters/oracle_adapter.rb b/lib/rails_sql_views/connection_adapters/oracle_adapter.rb index 2ecfb00..b91aa5a 100644 --- a/lib/rails_sql_views/connection_adapters/oracle_adapter.rb +++ b/lib/rails_sql_views/connection_adapters/oracle_adapter.rb @@ -6,7 +6,7 @@ def supports_views? true end - def tables(name = nil) #:nodoc: + def nonview_tables(name = nil) #:nodoc: tables = [] execute("SELECT TABLE_NAME FROM USER_TABLES", name).each { |row| tables << row[0] } tables diff --git a/lib/rails_sql_views/connection_adapters/postgresql_adapter.rb b/lib/rails_sql_views/connection_adapters/postgresql_adapter.rb index 35cd86c..1230409 100644 --- a/lib/rails_sql_views/connection_adapters/postgresql_adapter.rb +++ b/lib/rails_sql_views/connection_adapters/postgresql_adapter.rb @@ -6,6 +6,17 @@ def supports_views? true end + def nonview_tables(name = nil) + q = <<-SQL + SELECT table_name, table_type + FROM information_schema.tables + WHERE table_schema IN (#{schemas}) + AND table_type = 'BASE_TABLE' + SQL + + query(q, name).map { |row| row[0] } + end + def views(name = nil) #:nodoc: q = <<-SQL SELECT table_name, table_type diff --git a/lib/rails_sql_views/connection_adapters/sqlserver_adapter.rb b/lib/rails_sql_views/connection_adapters/sqlserver_adapter.rb index e3f4ae3..26d927f 100644 --- a/lib/rails_sql_views/connection_adapters/sqlserver_adapter.rb +++ b/lib/rails_sql_views/connection_adapters/sqlserver_adapter.rb @@ -6,6 +6,12 @@ def supports_views? true end + # Get all of the non-view tables from the currently connected schema + def nonview_tables(name = nil) + # this is untested + select_values("SELECT table_name FROM information_schema.tables", name) + end + # Returns all the view names from the currently connected schema. def views(name = nil) select_values("SELECT table_name FROM information_schema.views", name) diff --git a/test/README b/test/README index 91aa232..2e9257e 100644 --- a/test/README +++ b/test/README @@ -25,6 +25,7 @@ If you would like to implement an adapter, it should go in lib/rails_sql_views/c of the other adapters currently implemented. Every adapter must implement the following methods: supports_views? + nonview_tables(name = nil) views(name = nil) view_select_statement(view, name=nil)