提交 2fb2913b 编写于 作者: R Rafael Mendonça França

Merge pull request #15237 from sgrif/sg-move-extract-scale

Move extract_scale to decimal type
...@@ -22,8 +22,8 @@ module Type # :nodoc: ...@@ -22,8 +22,8 @@ module Type # :nodoc:
class << self class << self
def extract_scale(sql_type) def extract_scale(sql_type)
case sql_type case sql_type
when /^(numeric|decimal|number)\((\d+)\)/i then 0 when /\((\d+)\)/ then 0
when /^(numeric|decimal|number)\((\d+)(,(\d+))\)/i then $4.to_i when /\((\d+)(,(\d+))\)/ then $3.to_i
end end
end end
end end
......
...@@ -4,6 +4,8 @@ module Type ...@@ -4,6 +4,8 @@ module Type
class Decimal < Value # :nodoc: class Decimal < Value # :nodoc:
include Numeric include Numeric
delegate :extract_scale, to: Type
def type def type
:decimal :decimal
end end
......
...@@ -3,10 +3,7 @@ module ConnectionAdapters ...@@ -3,10 +3,7 @@ module ConnectionAdapters
module Type module Type
class Value # :nodoc: class Value # :nodoc:
def type; end def type; end
def extract_scale(sql_type); end
def extract_scale(sql_type)
Type.extract_scale(sql_type)
end
def type_cast(value) def type_cast(value)
cast_value(value) unless value.nil? cast_value(value) unless value.nil?
......
...@@ -353,9 +353,9 @@ def test_schema_dump_keeps_large_precision_integer_columns_as_decimal ...@@ -353,9 +353,9 @@ def test_schema_dump_keeps_large_precision_integer_columns_as_decimal
output = standard_dump output = standard_dump
# Oracle supports precision up to 38 and it identifies decimals with scale 0 as integers # Oracle supports precision up to 38 and it identifies decimals with scale 0 as integers
if current_adapter?(:OracleAdapter) if current_adapter?(:OracleAdapter)
assert_match %r{t.integer\s+"atoms_in_universe",\s+precision: 38,\s+scale: 0}, output assert_match %r{t.integer\s+"atoms_in_universe",\s+precision: 38}, output
else else
assert_match %r{t.decimal\s+"atoms_in_universe",\s+precision: 55,\s+scale: 0}, output assert_match %r{t.decimal\s+"atoms_in_universe",\s+precision: 55}, output
end end
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册