aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-05-26 06:26:50 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-05-26 06:26:50 +0000
commit33e96f3cb39401a576f5d1bd0584a61223a266b8 (patch)
treec850a7f212571c3e496820118b1890b623f0d199
parent652fe645f6a199417f672965b1f4d4078d046f7d (diff)
downloadrails-33e96f3cb39401a576f5d1bd0584a61223a266b8.tar.gz
rails-33e96f3cb39401a576f5d1bd0584a61223a266b8.tar.bz2
rails-33e96f3cb39401a576f5d1bd0584a61223a266b8.zip
Oracle binary fixtures; pull fixture insertion into the adapters. Closes #7987.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6859 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--activerecord/CHANGELOG4
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb6
-rw-r--r--activerecord/lib/active_record/connection_adapters/oracle_adapter.rb36
-rwxr-xr-xactiverecord/lib/active_record/fixtures.rb4
-rw-r--r--activerecord/test/binary_test.rb2
5 files changed, 40 insertions, 12 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 71839d0d92..7e90571397 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -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]
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
index bc59f064aa..3b35a190f9 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
@@ -119,6 +119,12 @@ module ActiveRecord
# 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.
diff --git a/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb b/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb
index 74101cf09a..25eca87304 100644
--- a/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb
@@ -44,17 +44,9 @@ begin
# 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 @@ begin
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
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb
index c837fd7b50..47a77e4249 100755
--- a/activerecord/lib/active_record/fixtures.rb
+++ b/activerecord/lib/active_record/fixtures.rb
@@ -290,7 +290,7 @@ class Fixtures < YAML::Omap
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 Fixture #:nodoc:
class FormatError < FixtureError#:nodoc:
end
+ attr_reader :class_name
+
def initialize(fixture, class_name)
case fixture
when Hash, YAML::Omap
diff --git a/activerecord/test/binary_test.rb b/activerecord/test/binary_test.rb
index 38a5d50935..3e35f1754f 100644
--- a/activerecord/test/binary_test.rb
+++ b/activerecord/test/binary_test.rb
@@ -20,7 +20,7 @@ class BinaryTest < Test::Unit::TestCase
# 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