Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Oracle binary fixtures; pull fixture insertion into the adapters. Clo…

…ses #7987.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6859 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 33e96f3cb39401a576f5d1bd0584a61223a266b8 1 parent 652fe64
Jeremy Kemper jeremy authored
4 activerecord/CHANGELOG
View
@@ -1,5 +1,9 @@
*SVN*
+* Oracle: support binary fixtures. #7987 [Michael Schoen]
+
+* Fixtures: pull fixture insertion into the database adapters. #7987 [Michael Schoen]
+
* Announce migration versions as they're performed. [Jeremy Kemper]
* find gracefully copes with blank :conditions. #7599 [Dan Manges, johnnyb]
6 activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
View
@@ -119,6 +119,12 @@ def reset_sequence!(table, column, sequence = nil)
# Do nothing by default. Implement for PostgreSQL, Oracle, ...
end
+ # Inserts the given fixture into the table. Overriden in adapters that require
+ # something beyond a simple insert (eg. Oracle).
+ def insert_fixture(fixture, table_name)
+ execute "INSERT INTO #{table_name} (#{fixture.key_list}) VALUES (#{fixture.value_list})", 'Fixture Insert'
+ end
+
protected
# Returns an array of record hashes with the column names as keys and
# column values as values.
36 activerecord/lib/active_record/connection_adapters/oracle_adapter.rb
View
@@ -44,17 +44,9 @@ def self.oci_connection(config) #:nodoc:
# After setting large objects to empty, select the OCI8::LOB
# and write back the data.
after_save :write_lobs
- def write_lobs() #:nodoc:
+ def write_lobs #:nodoc:
if connection.is_a?(ConnectionAdapters::OracleAdapter)
- self.class.columns.select { |c| c.sql_type =~ /LOB$/i }.each { |c|
- value = self[c.name]
- value = value.to_yaml if unserializable_attribute?(c.name, c)
- next if value.nil? || (value == '')
- lob = connection.select_one(
- "SELECT #{c.name} FROM #{self.class.table_name} WHERE #{self.class.primary_key} = #{quote_value(id)}",
- 'Writable Large Object')[c.name]
- lob.write value
- }
+ connection.write_lobs(self.class.table_name, self.class, attributes)
end
end
@@ -273,6 +265,30 @@ def default_sequence_name(table, column) #:nodoc:
end
+ # Inserts the given fixture into the table. Overriden to properly handle lobs.
+ def insert_fixture(fixture, table_name)
+ super
+
+ klass = fixture.class_name.constantize rescue nil
+ if klass.respond_to?(:ancestors) && klass.ancestors.include?(ActiveRecord::Base)
+ write_lobs(table_name, klass, fixture)
+ end
+ end
+
+ # Writes LOB values from attributes, as indicated by the LOB columns of klass.
+ def write_lobs(table_name, klass, attributes)
+ id = quote(attributes[klass.primary_key])
+ klass.columns.select { |col| col.sql_type =~ /LOB$/i }.each do |col|
+ value = attributes[col.name]
+ value = value.to_yaml if col.text? && klass.serialized_attributes[col.name]
+ next if value.nil? || (value == '')
+ lob = select_one("SELECT #{col.name} FROM #{table_name} WHERE #{klass.primary_key} = #{id}",
+ 'Writable Large Object')[col.name]
+ lob.write value
+ end
+ end
+
+
# SCHEMA STATEMENTS ========================================
#
# see: abstract/schema_statements.rb
4 activerecord/lib/active_record/fixtures.rb
View
@@ -290,7 +290,7 @@ def delete_existing_fixtures
def insert_fixtures
values.each do |fixture|
- @connection.execute "INSERT INTO #{@table_name} (#{fixture.key_list}) VALUES (#{fixture.value_list})", 'Fixture Insert'
+ @connection.insert_fixture fixture, @table_name
end
end
@@ -381,6 +381,8 @@ class FixtureError < StandardError#:nodoc:
class FormatError < FixtureError#:nodoc:
end
+ attr_reader :class_name
+
def initialize(fixture, class_name)
case fixture
when Hash, YAML::Omap
2  activerecord/test/binary_test.rb
View
@@ -20,7 +20,7 @@ def test_truth
# Without using prepared statements, it makes no sense to test
# BLOB data with DB2 or Firebird, because the length of a statement
# is limited to 32KB.
- unless %w(SQLServer Sybase DB2 Oracle Firebird).include? ActiveRecord::Base.connection.adapter_name
+ unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :DB2Adapter, :FirebirdAdapter)
def test_load_save
bin = Binary.new
bin.data = @data
Please sign in to comment.
Something went wrong with that request. Please try again.