module ActiveRecord::ConnectionAdapters::SQLServer::SchemaStatements

Public Instance Methods

view_information(table_name) click to toggle source
# File lib/hive_sql.rb, line 82
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