aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-10-08 06:17:53 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-10-08 06:17:53 +0000
commit4eaa8ba5bec9001e97349e7dfd565c7215085834 (patch)
tree5ef58d001fcbb69b36f505fac7bb29d6ba4d4c5e
parent99c64829ce71ecf07b576960ea8ff01dfee61be7 (diff)
downloadrails-4eaa8ba5bec9001e97349e7dfd565c7215085834.tar.gz
rails-4eaa8ba5bec9001e97349e7dfd565c7215085834.tar.bz2
rails-4eaa8ba5bec9001e97349e7dfd565c7215085834.zip
PostgreSQL: support multiline default values. Closes #7533.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7801 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb28
-rw-r--r--activerecord/test/defaults_test.rb6
-rw-r--r--activerecord/test/fixtures/db_definitions/postgresql.sql3
4 files changed, 24 insertions, 15 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 2c1f8d7bd9..fd5bf2f174 100644
--- a/activerecord/CHANGELOG
+++ b/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]
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 331f331de7..a5d550c84b 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -160,45 +160,45 @@ module ActiveRecord
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
diff --git a/activerecord/test/defaults_test.rb b/activerecord/test/defaults_test.rb
index 39dcc82b49..965dd956b0 100644
--- a/activerecord/test/defaults_test.rb
+++ b/activerecord/test/defaults_test.rb
@@ -57,4 +57,10 @@ class DefaultTest < Test::Unit::TestCase
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
diff --git a/activerecord/test/fixtures/db_definitions/postgresql.sql b/activerecord/test/fixtures/db_definitions/postgresql.sql
index 3b929e338c..5e38978e21 100644
--- a/activerecord/test/fixtures/db_definitions/postgresql.sql
+++ b/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 (