Sha256: 79e9017e9746fd66cfd25876dce5fb1bb362590953e67331898f0a5008ec0630

Contents?: true

Size: 1.22 KB

Versions: 14

Compression:

Stored size: 1.22 KB

Contents

module RailsSqlViews
  module ConnectionAdapters
    module SQLServerAdapter
      # Returns true as this adapter supports views.
      def supports_views?
        true
      end
      
      # Get all of the non-view tables from the currently connected schema
      def base_tables(name = nil)
        # this is untested
        select_values("SELECT table_name FROM information_schema.tables", name)
      end
      alias nonview_tables base_tables
      
      # Returns all the view names from the currently connected schema.
      def views(name = nil)
        select_values("SELECT table_name FROM information_schema.views", name)
      end
      
      # Get the view select statement for the specified view.
      def view_select_statement(view, name=nil)
        q =<<-ENDSQL
          SELECT view_definition FROM information_schema.views
          WHERE table_name = '#{view}'
        ENDSQL
        
        view_def = select_value(q, name)
        
        if view_def
          return convert_statement(view_def)
        else
          raise "No view called #{view} found"
        end
      end
      
      private
      def convert_statement(s)
        s.sub(/^CREATE.* AS (select .*)/i, '\1').gsub(/\n/, '')
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 7 rubygems

Version Path
robdimarco_rails_sql_views-0.9.0 lib/rails_sql_views/connection_adapters/sqlserver_adapter.rb
qubole_rails_sql_views-0.10.0 lib/rails_sql_views/connection_adapters/sqlserver_adapter.rb
lunks-rails_sql_views-0.9.2 lib/rails_sql_views/connection_adapters/sqlserver_adapter.rb
ctreatma-rails_sql_views-0.9.1 lib/rails_sql_views/connection_adapters/sqlserver_adapter.rb
ctreatma-rails_sql_views-0.9.0 lib/rails_sql_views/connection_adapters/sqlserver_adapter.rb
molo-0.7.6 vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/sqlserver_adapter.rb
molo-0.7.5 vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/sqlserver_adapter.rb
molo-0.7.4 vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/sqlserver_adapter.rb
molo-0.7.3 vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/sqlserver_adapter.rb
molo-0.7.2 vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/sqlserver_adapter.rb
molo-0.7.1 vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/sqlserver_adapter.rb
molo-0.7.0 vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/sqlserver_adapter.rb
rails_sql_views-0.8.0 lib/rails_sql_views/connection_adapters/sqlserver_adapter.rb
rubaidh-rails_sql_views-0.7.1 lib/rails_sql_views/connection_adapters/sqlserver_adapter.rb