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

Changeset 6859

Show
Ignore:
Timestamp:
05/26/07 06:26:50 (1 year ago)
Author:
bitsweat
Message:

Oracle binary fixtures; pull fixture insertion into the adapters. Closes #7987.

Files:

Legend:

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

    r6855 r6859  
    11*SVN* 
     2 
     3* Oracle: support binary fixtures.  #7987 [Michael Schoen] 
     4 
     5* Fixtures: pull fixture insertion into the database adapters.  #7987 [Michael Schoen] 
    26 
    37* Announce migration versions as they're performed.  [Jeremy Kemper] 
  • trunk/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb

    r6754 r6859  
    120120      end 
    121121 
     122      # Inserts the given fixture into the table. Overriden in adapters that require 
     123      # something beyond a simple insert (eg. Oracle). 
     124      def insert_fixture(fixture, table_name) 
     125        execute "INSERT INTO #{table_name} (#{fixture.key_list}) VALUES (#{fixture.value_list})", 'Fixture Insert' 
     126      end 
     127 
    122128      protected 
    123129        # Returns an array of record hashes with the column names as keys and 
  • trunk/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb

    r6738 r6859  
    4545      # and write back the data. 
    4646      after_save :write_lobs 
    47       def write_lobs() #:nodoc: 
     47      def write_lobs #:nodoc: 
    4848        if connection.is_a?(ConnectionAdapters::OracleAdapter) 
    49           self.class.columns.select { |c| c.sql_type =~ /LOB$/i }.each { |c| 
    50             value = self[c.name] 
    51             value = value.to_yaml if unserializable_attribute?(c.name, c) 
    52             next if value.nil?  || (value == '') 
    53             lob = connection.select_one( 
    54               "SELECT #{c.name} FROM #{self.class.table_name} WHERE #{self.class.primary_key} = #{quote_value(id)}", 
    55               'Writable Large Object')[c.name] 
    56             lob.write value 
    57           } 
     49          connection.write_lobs(self.class.table_name, self.class, attributes) 
    5850        end 
    5951      end 
     
    274266 
    275267 
     268        # Inserts the given fixture into the table. Overriden to properly handle lobs. 
     269        def insert_fixture(fixture, table_name) 
     270          super 
     271 
     272          klass = fixture.class_name.constantize rescue nil 
     273          if klass.respond_to?(:ancestors) && klass.ancestors.include?(ActiveRecord::Base) 
     274            write_lobs(table_name, klass, fixture) 
     275          end 
     276        end 
     277 
     278        # Writes LOB values from attributes, as indicated by the LOB columns of klass. 
     279        def write_lobs(table_name, klass, attributes) 
     280          id = quote(attributes[klass.primary_key]) 
     281          klass.columns.select { |col| col.sql_type =~ /LOB$/i }.each do |col| 
     282            value = attributes[col.name] 
     283            value = value.to_yaml if col.text? && klass.serialized_attributes[col.name] 
     284            next if value.nil?  || (value == '') 
     285            lob = select_one("SELECT #{col.name} FROM #{table_name} WHERE #{klass.primary_key} = #{id}", 
     286                             'Writable Large Object')[col.name] 
     287            lob.write value 
     288          end 
     289        end 
     290 
     291 
    276292        # SCHEMA STATEMENTS ======================================== 
    277293        # 
  • trunk/activerecord/lib/active_record/fixtures.rb

    r6798 r6859  
    291291  def insert_fixtures 
    292292    values.each do |fixture| 
    293       @connection.execute "INSERT INTO #{@table_name} (#{fixture.key_list}) VALUES (#{fixture.value_list})", 'Fixture Insert' 
     293      @connection.insert_fixture fixture, @table_name 
    294294    end 
    295295  end 
     
    381381  class FormatError < FixtureError#:nodoc: 
    382382  end 
     383 
     384  attr_reader :class_name 
    383385 
    384386  def initialize(fixture, class_name) 
  • trunk/activerecord/test/binary_test.rb

    r3905 r6859  
    2121  # BLOB data with DB2 or Firebird, because the length of a statement 
    2222  # is limited to 32KB. 
    23   unless %w(SQLServer Sybase DB2 Oracle Firebird).include? ActiveRecord::Base.connection.adapter_name 
     23  unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :DB2Adapter, :FirebirdAdapter) 
    2424    def test_load_save 
    2525      bin = Binary.new