mirror of
https://github.com/github/rails.git
synced 2026-04-04 03:00:58 -04:00
Oracle: fix lob and text default handling. Closes #7344.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6090 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
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
|
||||
assert_nothing_raised {
|
||||
Person.connection.create_table :binary_testings do |t|
|
||||
t.column "data", :binary, :null => false
|
||||
end
|
||||
}
|
||||
|
||||
Person.connection.drop_table :binary_testings rescue nil
|
||||
end
|
||||
columns = Person.connection.columns(:binary_testings)
|
||||
data_column = columns.detect { |c| c.name == "data" }
|
||||
|
||||
assert_nil data_column.default
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user