diff options
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/oracle_adapter.rb | 12 | ||||
-rw-r--r-- | activerecord/test/migration_test.rb | 37 |
3 files changed, 31 insertions, 20 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 6246e5a4c2..d1504d8486 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Oracle: fix lob and text default handling. #7344 [gfriedrich, Michael Schoen] + * SQLServer: don't choke on strings containing 'null'. #7083 [Jakob S] * MySQL: blob and text columns may not have defaults in 5.x. Update fixtures schema for strict mode. #6695 [Dan Kubb] diff --git a/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb b/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb index 4e7c3c395c..7e6ef121e2 100644 --- a/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb @@ -170,7 +170,7 @@ begin end def quote(value, column = nil) #:nodoc: - if column && [:text, :binary].include?(column.type) + if value && column && [:text, :binary].include?(column.type) %Q{empty_#{ column.sql_type.downcase rescue 'blob' }()} else super @@ -338,7 +338,7 @@ begin if row['data_default'] row['data_default'].sub!(/^(.*?)\s*$/, '\1') row['data_default'].sub!(/^'(.*)'$/, '\1') - row['data_default'] = nil if row['data_default'] =~ /^null$/i + row['data_default'] = nil if row['data_default'] =~ /^(null|empty_[bc]lob\(\))$/i end OracleColumn.new(oracle_downcase(row['name']), @@ -447,6 +447,14 @@ begin end end + def add_column_options!(sql, options) #:nodoc: + # handle case of defaults for CLOB columns, which would otherwise get "quoted" incorrectly + if options_include_default?(options) && (column = options[:column]) && column.type == :text + sql << " DEFAULT #{quote(options.delete(:default))}" + end + super + end + # SELECT DISTINCT clause for a given set of columns and a given ORDER BY clause. # # Oracle requires the ORDER BY columns to be in the SELECT list for DISTINCT diff --git a/activerecord/test/migration_test.rb b/activerecord/test/migration_test.rb index 0757c6a0c9..3cc8c18988 100644 --- a/activerecord/test/migration_test.rb +++ b/activerecord/test/migration_test.rb @@ -113,6 +113,7 @@ if ActiveRecord::Base.connection.supports_migrations? t.column :two, :boolean, :default => true t.column :three, :boolean, :default => false t.column :four, :integer, :default => 1 + t.column :five, :text, :default => "hello" end columns = Person.connection.columns(:testings) @@ -120,11 +121,13 @@ if ActiveRecord::Base.connection.supports_migrations? two = columns.detect { |c| c.name == "two" } three = columns.detect { |c| c.name == "three" } four = columns.detect { |c| c.name == "four" } + five = columns.detect { |c| c.name == "five" } assert_equal "hello", one.default assert_equal true, two.default assert_equal false, three.default assert_equal 1, four.default + assert_equal "hello", five.default ensure Person.connection.drop_table :testings rescue nil @@ -435,6 +438,8 @@ if ActiveRecord::Base.connection.supports_migrations? Person.reset_column_information assert !Person.new.contributor? assert_nil Person.new.contributor + ensure + Person.connection.remove_column("people", "contributor") rescue nil end def test_change_column_with_new_default @@ -445,6 +450,8 @@ if ActiveRecord::Base.connection.supports_migrations? assert_nothing_raised { Person.connection.change_column "people", "administrator", :boolean, :default => false } Person.reset_column_information assert !Person.new.administrator? + ensure + Person.connection.remove_column("people", "administrator") rescue nil end def test_change_column_default @@ -685,29 +692,23 @@ if ActiveRecord::Base.connection.supports_migrations? Reminder.reset_sequence_name end -# FrontBase does not support default values on BLOB/CLOB columns - unless current_adapter?(:FrontBaseAdapter) - def test_create_table_with_binary_column - Person.connection.drop_table :binary_testings rescue nil + def test_create_table_with_binary_column + Person.connection.drop_table :binary_testings rescue nil - assert_nothing_raised { - Person.connection.create_table :binary_testings do |t| - t.column "data", :binary, :null => false - end - } + assert_nothing_raised { + Person.connection.create_table :binary_testings do |t| + t.column "data", :binary, :null => false + end + } - columns = Person.connection.columns(:binary_testings) - data_column = columns.detect { |c| c.name == "data" } + columns = Person.connection.columns(:binary_testings) + data_column = columns.detect { |c| c.name == "data" } - if current_adapter?(:OracleAdapter) - assert_equal "empty_blob()", data_column.default - else - assert_nil data_column.default - end + assert_nil data_column.default - Person.connection.drop_table :binary_testings rescue nil - end + Person.connection.drop_table :binary_testings rescue nil end + def test_migrator_with_duplicates assert_raises(ActiveRecord::DuplicateMigrationVersionError) do ActiveRecord::Migrator.migrate(File.dirname(__FILE__) + '/fixtures/migrations_with_duplicate/', nil) |