Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

PostgreSQL: support multiline default values. Closes #7533.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7801 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 4eaa8ba5bec9001e97349e7dfd565c7215085834 1 parent 99c6482
@jeremy jeremy authored
View
2  activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* PostgreSQL: support multiline default values. #7533 [Carl Lerche, aguynamedryan, Rein Henrichs, Tarmo Tänav]
+
* MySQL: fix change_column on not-null columns that don't accept dfeault values of ''. #6663 [Jonathan Viney, Tarmo Tänav]
* validates_uniqueness_of behaves well with single-table inheritance. #3833 [Gabriel Gironda, rramdas, François Beausoleil, Josh Peek, Tarmo Tänav]
View
28 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -160,45 +160,45 @@ def simplified_type(field_type)
def self.extract_value_from_default(default)
case default
# Numeric types
- when /^-?\d+(\.\d*)?$/
+ when /\A-?\d+(\.\d*)?\z/
default
# Character types
- when /^'(.*)'::(?:character varying|bpchar|text)$/
+ when /\A'(.*)'::(?:character varying|bpchar|text)\z/m
$1
# Binary data types
- when /^'(.*)'::bytea$/
+ when /\A'(.*)'::bytea\z/m
$1
# Date/time types
- when /^'(.+)'::(?:time(?:stamp)? with(?:out)? time zone|date)$/
+ when /\A'(.+)'::(?:time(?:stamp)? with(?:out)? time zone|date)\z/
$1
- when /^'(.*)'::interval$/
+ when /\A'(.*)'::interval\z/
$1
# Boolean type
- when /^true$/
+ when 'true'
true
- when /^false$/
+ when 'false'
false
# Geometric types
- when /^'(.*)'::(?:point|line|lseg|box|"?path"?|polygon|circle)$/
+ when /\A'(.*)'::(?:point|line|lseg|box|"?path"?|polygon|circle)\z/
$1
# Network address types
- when /^'(.*)'::(?:cidr|inet|macaddr)$/
+ when /\A'(.*)'::(?:cidr|inet|macaddr)\z/
$1
# Bit string types
- when /^B'(.*)'::"?bit(?: varying)?"?$/
+ when /\AB'(.*)'::"?bit(?: varying)?"?\z/
$1
# XML type
- when /^'(.*)'::xml$/
+ when /\A'(.*)'::xml\z/m
$1
# Arrays
- when /^'(.*)'::"?\D+"?\[\]$/
+ when /\A'(.*)'::"?\D+"?\[\]\z/
$1
# Object identifier types
- when /^-?\d+$/
+ when /\A-?\d+\z/
$1
else
# Anything else is blank, some user type, or some function
- # and we can't know the value of that, so return nil.
+ # and we can't know the value of that, so return nil.
nil
end
end
View
6 activerecord/test/defaults_test.rb
@@ -57,4 +57,10 @@ def test_default_integers
assert_equal BigDecimal.new("2.78"), default.decimal_number
end
end
+
+ if current_adapter?(:PostgreSQLAdapter)
+ def test_multiline_default_text
+ assert_equal "--- []\n\n", Default.columns_hash['multiline_default'].default
+ end
+ end
end
View
3  activerecord/test/fixtures/db_definitions/postgresql.sql
@@ -109,7 +109,8 @@ CREATE TABLE defaults (
char3 text default 'a text field',
positive_integer integer default 1,
negative_integer integer default -1,
- decimal_number decimal(3,2) default 2.78
+ decimal_number decimal(3,2) default 2.78,
+ multiline_default text DEFAULT E'--- []\n\n'::text
);
CREATE TABLE auto_id_tests (
Please sign in to comment.
Something went wrong with that request. Please try again.