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

Ticket #7987: ora_binary_fixtures.patch

File ora_binary_fixtures.patch, 4.6 kB (added by mschoen, 1 year ago)
  • activerecord/test/binary_test.rb

    old new  
    2020  # Without using prepared statements, it makes no sense to test 
    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 
    2626      bin.data = @data 
  • activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb

    old new  
    119119        # Do nothing by default.  Implement for PostgreSQL, Oracle, ... 
    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 
    124130        # column values as values. 
  • activerecord/lib/active_record/connection_adapters/oracle_adapter.rb

    old new  
    4444      # After setting large objects to empty, select the OCI8::LOB 
    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 
    6052 
     
    273265        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        # 
    278294        # see: abstract/schema_statements.rb 
  • activerecord/lib/active_record/fixtures.rb

    old new  
    290290 
    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 
    296296 
     
    381381  class FormatError < FixtureError#:nodoc: 
    382382  end 
    383383 
     384  attr_reader :class_name 
     385 
    384386  def initialize(fixture, class_name) 
    385387    case fixture 
    386388      when Hash, YAML::Omap