Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
ca703bbc
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,发现更多精彩内容 >>
提交
ca703bbc
编写于
5月 20, 2014
作者:
S
Sean Griffin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use general types for mysql fields
上级
89ca6806
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
11 addition
and
69 deletion
+11
-69
activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
...rd/lib/active_record/connection_adapters/mysql_adapter.rb
+11
-69
未找到文件。
activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
浏览文件 @
ca703bbc
...
...
@@ -283,39 +283,7 @@ def last_inserted_id(result)
end
module
Fields
class
Type
def
type
;
end
def
type_cast_for_write
(
value
)
value
end
end
class
Identity
<
Type
def
type_cast
(
value
);
value
;
end
end
class
Integer
<
Type
def
type_cast
(
value
)
return
if
value
.
nil?
value
.
to_i
rescue
value
?
1
:
0
end
end
class
Date
<
Type
def
type
;
:date
;
end
def
type_cast
(
value
)
return
if
value
.
nil?
# FIXME: probably we can improve this since we know it is mysql
# specific
ConnectionAdapters
::
Column
.
value_to_date
value
end
end
class
DateTime
<
ConnectionAdapters
::
Type
::
DateTime
class
DateTime
<
Type
::
DateTime
def
cast_value
(
value
)
if
Mysql
::
Time
===
value
new_time
(
...
...
@@ -332,7 +300,7 @@ def cast_value(value)
end
end
class
Time
<
ConnectionAdapters
::
Type
::
Time
class
Time
<
Type
::
Time
def
cast_value
(
value
)
if
Mysql
::
Time
===
value
new_time
(
...
...
@@ -349,32 +317,6 @@ def cast_value(value)
end
end
class
Float
<
Type
def
type
;
:float
;
end
def
type_cast
(
value
)
return
if
value
.
nil?
value
.
to_f
end
end
class
Decimal
<
Type
def
type_cast
(
value
)
return
if
value
.
nil?
ConnectionAdapters
::
Column
.
value_to_decimal
value
end
end
class
Boolean
<
Type
def
type_cast
(
value
)
return
if
value
.
nil?
ConnectionAdapters
::
Column
.
value_to_boolean
value
end
end
TYPES
=
{}
# Register an MySQL +type_id+ with a typecasting object in
...
...
@@ -391,26 +333,26 @@ def self.find_type(field)
if
field
.
type
==
Mysql
::
Field
::
TYPE_TINY
&&
field
.
length
>
1
TYPES
[
Mysql
::
Field
::
TYPE_LONG
]
else
TYPES
.
fetch
(
field
.
type
)
{
Fields
::
Identity
.
new
}
TYPES
.
fetch
(
field
.
type
)
{
Type
::
Value
.
new
}
end
end
register_type
Mysql
::
Field
::
TYPE_TINY
,
Fields
::
Boolean
.
new
register_type
Mysql
::
Field
::
TYPE_LONG
,
Fields
::
Integer
.
new
register_type
Mysql
::
Field
::
TYPE_TINY
,
Type
::
Boolean
.
new
register_type
Mysql
::
Field
::
TYPE_LONG
,
Type
::
Integer
.
new
alias_type
Mysql
::
Field
::
TYPE_LONGLONG
,
Mysql
::
Field
::
TYPE_LONG
alias_type
Mysql
::
Field
::
TYPE_NEWDECIMAL
,
Mysql
::
Field
::
TYPE_LONG
register_type
Mysql
::
Field
::
TYPE_VAR_STRING
,
Fields
::
Identity
.
new
register_type
Mysql
::
Field
::
TYPE_BLOB
,
Fields
::
Identity
.
new
register_type
Mysql
::
Field
::
TYPE_DATE
,
Fields
::
Date
.
new
register_type
Mysql
::
Field
::
TYPE_VAR_STRING
,
Type
::
Value
.
new
register_type
Mysql
::
Field
::
TYPE_BLOB
,
Type
::
Value
.
new
register_type
Mysql
::
Field
::
TYPE_DATE
,
Type
::
Date
.
new
register_type
Mysql
::
Field
::
TYPE_DATETIME
,
Fields
::
DateTime
.
new
register_type
Mysql
::
Field
::
TYPE_TIME
,
Fields
::
Time
.
new
register_type
Mysql
::
Field
::
TYPE_FLOAT
,
Fields
::
Float
.
new
register_type
Mysql
::
Field
::
TYPE_FLOAT
,
Type
::
Float
.
new
Mysql
::
Field
.
constants
.
grep
(
/TYPE/
).
map
{
|
class_name
|
Mysql
::
Field
.
const_get
class_name
}.
reject
{
|
const
|
TYPES
.
key?
const
}.
each
do
|
const
|
register_type
const
,
Fields
::
Identity
.
new
register_type
const
,
Type
::
Value
.
new
end
end
...
...
@@ -435,7 +377,7 @@ def exec_without_stmt(sql, name = 'SQL') # :nodoc:
fields
<<
field_name
if
field
.
decimals
>
0
types
[
field_name
]
=
Fields
::
Decimal
.
new
types
[
field_name
]
=
Type
::
Decimal
.
new
else
types
[
field_name
]
=
Fields
.
find_type
field
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录