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

Ticket #5630: mysql_prefix_indexes.diff

File mysql_prefix_indexes.diff, 2.0 kB (added by fastjames@gmail.com, 2 years ago)

Diff to allow prefix indexes to be specified in column names.

  • activerecord/test/adapter_test.rb

    old new  
    4040    @connection.remove_index(:accounts, :name => idx_name) rescue nil 
    4141  end 
    4242   
     43  def test_prefix_indexes 
     44    idx_name = "comments_idx" 
     45       
     46    if @connection.respond_to?(:indexes) 
     47      indexes = @connection.indexes("comments") 
     48      assert indexes.empty? 
     49 
     50      @connection.add_index :comments, 'body(200)', :name => idx_name 
     51      indexes = @connection.indexes("comments") 
     52      assert_equal "comments", indexes.first.table 
     53      # OpenBase does not have the concept of a named index 
     54      # Indexes are merely properties of columns. 
     55      assert_equal idx_name, indexes.first.name unless current_adapter?(:OpenBaseAdapter) 
     56      assert !indexes.first.unique 
     57      assert_equal ["body"], indexes.first.columns 
     58    else 
     59      warn "#{@connection.class} does not respond to #indexes" 
     60    end 
     61 
     62  ensure 
     63    @connection.remove_index(:comments, :name => idx_name) rescue nil 
     64  end 
     65   
    4366  def test_current_database 
    4467    if @connection.respond_to?(:current_database) 
    4568      assert_equal ENV['ARUNIT_DB_NAME'] || "activerecord_unittest", @connection.current_database 
  • activerecord/lib/active_record/connection_adapters/mysql_adapter.rb

    old new  
    124124      end 
    125125 
    126126      def quote_column_name(name) #:nodoc: 
    127         "`#{name}`" 
     127        re = /\((\d+)\)\Z/ 
     128        if md = re.match(name.to_s) 
     129          index_length = md[1] 
     130          name.gsub!(re, '') 
     131          "`#{name}`(#{index_length})" 
     132        else 
     133          "`#{name}`" 
     134        end 
    128135      end 
    129136 
    130137      def quote_string(string) #:nodoc: