Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
73f1ab21
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
73f1ab21
编写于
5月 22, 2014
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #15250 from sgrif/sg-push-scale-to-types
Push scale to type objects
上级
70ec49c8
57cc778f
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
27 addition
and
20 deletion
+27
-20
activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
...lib/active_record/connection_adapters/abstract_adapter.rb
+11
-2
activerecord/lib/active_record/connection_adapters/column.rb
activerecord/lib/active_record/connection_adapters/column.rb
+3
-4
activerecord/lib/active_record/connection_adapters/postgresql/oid/money.rb
...active_record/connection_adapters/postgresql/oid/money.rb
+1
-1
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
...b/active_record/connection_adapters/postgresql_adapter.rb
+5
-1
activerecord/lib/active_record/connection_adapters/type.rb
activerecord/lib/active_record/connection_adapters/type.rb
+0
-8
activerecord/lib/active_record/connection_adapters/type/decimal.rb
...ord/lib/active_record/connection_adapters/type/decimal.rb
+0
-2
activerecord/lib/active_record/connection_adapters/type/value.rb
...ecord/lib/active_record/connection_adapters/type/value.rb
+7
-2
未找到文件。
activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
浏览文件 @
73f1ab21
...
...
@@ -390,10 +390,12 @@ def initialize_type_map(m) # :nodoc:
m
.
alias_type
%r(double)i
,
'float'
m
.
register_type
%r(int)i
,
Type
::
Integer
.
new
m
.
register_type
(
%r(decimal)i
)
do
|
sql_type
|
if
Type
.
extract_scale
(
sql_type
)
==
0
scale
=
extract_scale
(
sql_type
)
if
scale
==
0
Type
::
Integer
.
new
else
Type
::
Decimal
.
new
Type
::
Decimal
.
new
(
scale:
scale
)
end
end
end
...
...
@@ -403,6 +405,13 @@ def reload_type_map # :nodoc:
initialize_type_map
(
type_map
)
end
def
extract_scale
(
sql_type
)
# :nodoc:
case
sql_type
when
/\((\d+)\)/
then
0
when
/\((\d+)(,(\d+))\)/
then
$3
.
to_i
end
end
def
translate_exception_class
(
e
,
sql
)
message
=
"
#{
e
.
class
.
name
}
:
#{
e
.
message
}
:
#{
sql
}
"
@logger
.
error
message
if
@logger
...
...
activerecord/lib/active_record/connection_adapters/column.rb
浏览文件 @
73f1ab21
...
...
@@ -13,12 +13,12 @@ module Format
ISO_DATETIME
=
/\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(\.\d+)?\z/
end
attr_reader
:name
,
:default
,
:cast_type
,
:limit
,
:null
,
:sql_type
,
:precision
,
:
scale
,
:
default_function
attr_reader
:name
,
:default
,
:cast_type
,
:limit
,
:null
,
:sql_type
,
:precision
,
:default_function
attr_accessor
:primary
,
:coder
alias
:encoded?
:coder
delegate
:type
,
:klass
,
:text?
,
:number?
,
:binary?
,
:type_cast_for_write
,
to: :cast_type
delegate
:type
,
:
scale
,
:
klass
,
:text?
,
:number?
,
:binary?
,
:type_cast_for_write
,
to: :cast_type
# Instantiates a new column in the table.
#
...
...
@@ -36,7 +36,6 @@ def initialize(name, default, cast_type, sql_type = nil, null = true)
@null
=
null
@limit
=
extract_limit
(
sql_type
)
@precision
=
extract_precision
(
sql_type
)
@scale
=
extract_scale
(
sql_type
)
@default
=
extract_default
(
default
)
@default_function
=
nil
@primary
=
nil
...
...
@@ -69,7 +68,7 @@ def extract_default(default)
end
private
delegate
:extract_
scale
,
:extract_
precision
,
to: :cast_type
delegate
:extract_precision
,
to: :cast_type
def
extract_limit
(
sql_type
)
$1
.
to_i
if
sql_type
=~
/\((.*)\)/
...
...
activerecord/lib/active_record/connection_adapters/postgresql/oid/money.rb
浏览文件 @
73f1ab21
...
...
@@ -7,7 +7,7 @@ class Money < Type::Decimal
class_attribute
:precision
def
extract_scale
(
sql_type
)
def
scale
2
end
...
...
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
浏览文件 @
73f1ab21
...
...
@@ -571,7 +571,6 @@ def initialize_type_map(m)
m
.
alias_type
'int4'
,
'int2'
m
.
alias_type
'int8'
,
'int2'
m
.
alias_type
'oid'
,
'int2'
m
.
register_type
'numeric'
,
OID
::
Decimal
.
new
m
.
register_type
'float4'
,
OID
::
Float
.
new
m
.
alias_type
'float8'
,
'float4'
m
.
register_type
'text'
,
Type
::
Text
.
new
...
...
@@ -610,6 +609,11 @@ def initialize_type_map(m)
m
.
alias_type
'lseg'
,
'varchar'
m
.
alias_type
'box'
,
'varchar'
m
.
register_type
'numeric'
do
|
_
,
sql_type
|
scale
=
extract_scale
(
sql_type
)
OID
::
Decimal
.
new
(
scale:
scale
)
end
load_additional_types
(
m
)
end
...
...
activerecord/lib/active_record/connection_adapters/type.rb
浏览文件 @
73f1ab21
...
...
@@ -19,14 +19,6 @@
module
ActiveRecord
module
ConnectionAdapters
module
Type
# :nodoc:
class
<<
self
def
extract_scale
(
sql_type
)
case
sql_type
when
/\((\d+)\)/
then
0
when
/\((\d+)(,(\d+))\)/
then
$3
.
to_i
end
end
end
end
end
end
activerecord/lib/active_record/connection_adapters/type/decimal.rb
浏览文件 @
73f1ab21
...
...
@@ -4,8 +4,6 @@ module Type
class
Decimal
<
Value
# :nodoc:
include
Numeric
delegate
:extract_scale
,
to:
Type
def
type
:decimal
end
...
...
activerecord/lib/active_record/connection_adapters/type/value.rb
浏览文件 @
73f1ab21
...
...
@@ -2,9 +2,14 @@ module ActiveRecord
module
ConnectionAdapters
module
Type
class
Value
# :nodoc:
def
type
;
end
attr_reader
:scale
def
initialize
(
options
=
{})
options
.
assert_valid_keys
(
:scale
)
@scale
=
options
[
:scale
]
end
def
extract_scale
(
sql_type
)
;
end
def
type
;
end
def
extract_precision
(
sql_type
);
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录