aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-05-22 10:30:15 -0700
committerSean Griffin <sean@thoughtbot.com>2014-05-22 12:04:31 -0700
commit22c27ae31f1b7c3a4e3b5cbcb4571c6be5e527e8 (patch)
treea66d30617830c7315efecd1beedeeccf9d74c1e8 /activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
parent73f1ab21855269eda57088ccf3f3fb8245d23426 (diff)
downloadrails-22c27ae31f1b7c3a4e3b5cbcb4571c6be5e527e8.tar.gz
rails-22c27ae31f1b7c3a4e3b5cbcb4571c6be5e527e8.tar.bz2
rails-22c27ae31f1b7c3a4e3b5cbcb4571c6be5e527e8.zip
Push precision to type objects
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract_adapter.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_adapter.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
index 875736350e..f3162419c7 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -391,11 +391,12 @@ module ActiveRecord
m.register_type %r(int)i, Type::Integer.new
m.register_type(%r(decimal)i) do |sql_type|
scale = extract_scale(sql_type)
+ precision = extract_precision(sql_type)
if scale == 0
- Type::Integer.new
+ Type::Integer.new(precision: precision)
else
- Type::Decimal.new(scale: scale)
+ Type::Decimal.new(precision: precision, scale: scale)
end
end
end
@@ -412,6 +413,10 @@ module ActiveRecord
end
end
+ def extract_precision(sql_type) # :nodoc:
+ $1.to_i if sql_type =~ /\((\d+)(,\d+)?\)/
+ end
+
def translate_exception_class(e, sql)
message = "#{e.class.name}: #{e.message}: #{sql}"
@logger.error message if @logger