Module: ActiveRecord::ConnectionAdapters::SQLServer::SchemaStatements

Defined in:
lib/hive_sql.rb

Instance Method Summary collapse

Instance Method Details

#view_information(table_name) ⇒ Object


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/hive_sql.rb', line 79

def view_information(table_name)
  @view_information ||= {}
  @view_information[table_name] ||= begin
    identifier = SQLServer::Utils.extract_identifiers(table_name)
    view_info = select_one "SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = #{quote(identifier.object)}", 'SCHEMA'
    if view_info
      view_info = view_info.with_indifferent_access
      if view_info[:VIEW_DEFINITION].blank? || view_info[:VIEW_DEFINITION].length == 4000
        view_info[:VIEW_DEFINITION] = begin
          select_values("EXEC sp_columns #{identifier.object_quoted}", 'SCHEMA').join
        rescue
          warn "No view definition found, possible permissions problem.\nPlease run GRANT VIEW DEFINITION TO your_user;"
          nil
        end
      end
    end
    view_info
  end
end