Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 3886

Show
Ignore:
Timestamp:
03/16/06 03:00:27 (3 years ago)
Author:
david
Message:

Stop the MySQL adapter crashing when views are present. (closes #3782) [Jonathan Viney]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r3882 r3886  
    106106* Documentation fixes for :dependent [robby@planetargon.com] 
    107107 
     108* Stop the MySQL adapter crashing when views are present. #3782 [Jonathan Viney] 
     109 
    108110* Allow set_fixture_class to take Classes instead of strings for a class in a module.  Raise FixtureClassNotFound if a fixture can't load.  [Rick Olson] 
    109111 
  • trunk/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb

    r3674 r3886  
    237237 
    238238      def structure_dump #:nodoc: 
    239         select_all("SHOW TABLES").inject("") do |structure, table| 
     239        if supports_views? 
     240          sql = "SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'" 
     241        else 
     242          sql = "SHOW TABLES" 
     243        end 
     244         
     245        select_all(sql).inject("") do |structure, table| 
     246          table.delete('Table_type') 
    240247          structure += select_one("SHOW CREATE TABLE #{table.to_a.first.last}")["Create Table"] + ";\n\n" 
    241248        end 
     
    335342          rows 
    336343        end 
     344         
     345        def supports_views? 
     346          version[0] >= 5 
     347        end 
     348         
     349        def version 
     350          @version ||= @connection.server_info.scan(/^(\d+)\.(\d+)\.(\d+)/).flatten.map { |v| v.to_i } 
     351        end 
    337352    end 
    338353  end