Changeset 6859
- Timestamp:
- 05/26/07 06:26:50 (1 year ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb (modified) (2 diffs)
- trunk/activerecord/lib/active_record/fixtures.rb (modified) (2 diffs)
- trunk/activerecord/test/binary_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r6855 r6859 1 1 *SVN* 2 3 * Oracle: support binary fixtures. #7987 [Michael Schoen] 4 5 * Fixtures: pull fixture insertion into the database adapters. #7987 [Michael Schoen] 2 6 3 7 * Announce migration versions as they're performed. [Jeremy Kemper] trunk/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
r6754 r6859 120 120 end 121 121 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 122 128 protected 123 129 # 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 45 45 # and write back the data. 46 46 after_save :write_lobs 47 def write_lobs ()#:nodoc:47 def write_lobs #:nodoc: 48 48 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) 58 50 end 59 51 end … … 274 266 275 267 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 276 292 # SCHEMA STATEMENTS ======================================== 277 293 # trunk/activerecord/lib/active_record/fixtures.rb
r6798 r6859 291 291 def insert_fixtures 292 292 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 294 294 end 295 295 end … … 381 381 class FormatError < FixtureError#:nodoc: 382 382 end 383 384 attr_reader :class_name 383 385 384 386 def initialize(fixture, class_name) trunk/activerecord/test/binary_test.rb
r3905 r6859 21 21 # BLOB data with DB2 or Firebird, because the length of a statement 22 22 # is limited to 32KB. 23 unless %w(SQLServer Sybase DB2 Oracle Firebird).include? ActiveRecord::Base.connection.adapter_name23 unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :DB2Adapter, :FirebirdAdapter) 24 24 def test_load_save 25 25 bin = Binary.new