Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
8e4d014a
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,发现更多精彩内容 >>
提交
8e4d014a
编写于
5月 22, 2014
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #15256 from sgrif/sg-push-precision-to-types
Push precision to type objects
上级
73f1ab21
22c27ae3
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
27 addition
and
22 deletion
+27
-22
activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
...lib/active_record/connection_adapters/abstract_adapter.rb
+7
-2
activerecord/lib/active_record/connection_adapters/column.rb
activerecord/lib/active_record/connection_adapters/column.rb
+2
-5
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
...b/active_record/connection_adapters/postgresql_adapter.rb
+15
-3
activerecord/lib/active_record/connection_adapters/type/date_time.rb
...d/lib/active_record/connection_adapters/type/date_time.rb
+0
-4
activerecord/lib/active_record/connection_adapters/type/numeric.rb
...ord/lib/active_record/connection_adapters/type/numeric.rb
+0
-4
activerecord/lib/active_record/connection_adapters/type/value.rb
...ecord/lib/active_record/connection_adapters/type/value.rb
+3
-4
未找到文件。
activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
浏览文件 @
8e4d014a
...
...
@@ -391,11 +391,12 @@ def initialize_type_map(m) # :nodoc:
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 @@ def extract_scale(sql_type) # :nodoc:
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
...
...
activerecord/lib/active_record/connection_adapters/column.rb
浏览文件 @
8e4d014a
...
...
@@ -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
,
:
default_function
attr_reader
:name
,
:default
,
:cast_type
,
:limit
,
:null
,
:sql_type
,
:default_function
attr_accessor
:primary
,
:coder
alias
:encoded?
:coder
delegate
:type
,
:scale
,
:klass
,
:text?
,
:number?
,
:binary?
,
:type_cast_for_write
,
to: :cast_type
delegate
:type
,
:
precision
,
:
scale
,
:klass
,
:text?
,
:number?
,
:binary?
,
:type_cast_for_write
,
to: :cast_type
# Instantiates a new column in the table.
#
...
...
@@ -35,7 +35,6 @@ def initialize(name, default, cast_type, sql_type = nil, null = true)
@sql_type
=
sql_type
@null
=
null
@limit
=
extract_limit
(
sql_type
)
@precision
=
extract_precision
(
sql_type
)
@default
=
extract_default
(
default
)
@default_function
=
nil
@primary
=
nil
...
...
@@ -68,8 +67,6 @@ def extract_default(default)
end
private
delegate
:extract_precision
,
to: :cast_type
def
extract_limit
(
sql_type
)
$1
.
to_i
if
sql_type
=~
/\((.*)\)/
end
...
...
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
浏览文件 @
8e4d014a
...
...
@@ -551,6 +551,8 @@ def get_oid_type(oid, fmod, column_name, sql_type = '')
}
end
OID_FOR_DECIMAL_TREATED_AS_INT
=
23
# :nodoc:
def
normalize_oid_type
(
ftype
,
fmod
)
# The type for the numeric depends on the width of the field,
# so we'll do something special here.
...
...
@@ -560,7 +562,7 @@ def normalize_oid_type(ftype, fmod)
# places after decimal = fmod - 4 & 0xffff
# places before decimal = (fmod - 4) >> 16 & 0xffff
if
ftype
==
1700
&&
(
fmod
-
4
&
0xffff
).
zero?
23
OID_FOR_DECIMAL_TREATED_AS_INT
else
ftype
end
...
...
@@ -581,7 +583,6 @@ def initialize_type_map(m)
m
.
register_type
'bool'
,
Type
::
Boolean
.
new
m
.
register_type
'bit'
,
OID
::
Bit
.
new
m
.
alias_type
'varbit'
,
'bit'
m
.
register_type
'timestamp'
,
OID
::
DateTime
.
new
m
.
alias_type
'timestamptz'
,
'timestamp'
m
.
register_type
'date'
,
OID
::
Date
.
new
m
.
register_type
'time'
,
OID
::
Time
.
new
...
...
@@ -609,9 +610,20 @@ def initialize_type_map(m)
m
.
alias_type
'lseg'
,
'varchar'
m
.
alias_type
'box'
,
'varchar'
m
.
register_type
'timestamp'
do
|
_
,
sql_type
|
precision
=
extract_precision
(
sql_type
)
OID
::
DateTime
.
new
(
precision:
precision
)
end
m
.
register_type
'numeric'
do
|
_
,
sql_type
|
precision
=
extract_precision
(
sql_type
)
scale
=
extract_scale
(
sql_type
)
OID
::
Decimal
.
new
(
scale:
scale
)
OID
::
Decimal
.
new
(
precision:
precision
,
scale:
scale
)
end
m
.
register_type
OID_FOR_DECIMAL_TREATED_AS_INT
do
|
_
,
sql_type
|
precision
=
extract_precision
(
sql_type
)
OID
::
Integer
.
new
(
precision:
precision
)
end
load_additional_types
(
m
)
...
...
activerecord/lib/active_record/connection_adapters/type/date_time.rb
浏览文件 @
8e4d014a
...
...
@@ -8,10 +8,6 @@ def type
:datetime
end
def
extract_precision
(
sql_type
)
$1
.
to_i
if
sql_type
=~
/\((\d+)\)/
end
private
def
cast_value
(
string
)
...
...
activerecord/lib/active_record/connection_adapters/type/numeric.rb
浏览文件 @
8e4d014a
...
...
@@ -14,10 +14,6 @@ def type_cast_for_write(value)
else
super
end
end
def
extract_precision
(
sql_type
)
$1
.
to_i
if
sql_type
=~
/\((\d+)(,\d+)?\)/
end
end
end
end
...
...
activerecord/lib/active_record/connection_adapters/type/value.rb
浏览文件 @
8e4d014a
...
...
@@ -2,17 +2,16 @@ module ActiveRecord
module
ConnectionAdapters
module
Type
class
Value
# :nodoc:
attr_reader
:scale
attr_reader
:
precision
,
:
scale
def
initialize
(
options
=
{})
options
.
assert_valid_keys
(
:scale
)
options
.
assert_valid_keys
(
:precision
,
:scale
)
@precision
=
options
[
:precision
]
@scale
=
options
[
:scale
]
end
def
type
;
end
def
extract_precision
(
sql_type
);
end
def
type_cast
(
value
)
cast_value
(
value
)
unless
value
.
nil?
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录