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

Ticket #3782: fix_crash_with_mysql_views.patch

File fix_crash_with_mysql_views.patch, 1.8 kB (added by Jonathan, 3 years ago)
  • activerecord/lib/active_record/connection_adapters/mysql_adapter.rb

    old new  
    236236      # SCHEMA STATEMENTS ======================================== 
    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 
    242249      end 
     
    334341          result.free 
    335342          rows 
    336343        end 
     344         
     345        def supports_views? 
     346          version[0] >= 5 
     347        end 
     348         
     349        def version 
     350          @version ||= select_one("SELECT VERSION()")['VERSION()'].scan(/^(\d)\.(\d)\.(\d{1,2})/).flatten.map { |v| v.to_i } 
     351        end 
    337352    end 
    338353  end 
    339354end 
  • activerecord/CHANGELOG

    old new  
    11*SVN* 
    22 
     3* Stop the MySQL adapter crashing when views are present. #3782 [Jonathan Viney] 
     4 
    35* 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] 
    46 
    57* Fix quoting of inheritance column for STI eager loading #4098 [Jonathan Viney <jonathan@bluewire.net.nz>]