Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
36fde2b7
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,发现更多精彩内容 >>
提交
36fde2b7
编写于
5月 20, 2014
作者:
S
Sean Griffin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Delegate `#type_cast` to injected type objects on SQLite3
上级
528aff12
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
83 addition
and
7 deletion
+83
-7
activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
.../lib/active_record/connection_adapters/sqlite3_adapter.rb
+20
-6
activerecord/lib/active_record/connection_adapters/type/boolean.rb
...ord/lib/active_record/connection_adapters/type/boolean.rb
+6
-0
activerecord/lib/active_record/connection_adapters/type/date.rb
...record/lib/active_record/connection_adapters/type/date.rb
+6
-0
activerecord/lib/active_record/connection_adapters/type/date_time.rb
...d/lib/active_record/connection_adapters/type/date_time.rb
+6
-0
activerecord/lib/active_record/connection_adapters/type/decimal.rb
...ord/lib/active_record/connection_adapters/type/decimal.rb
+6
-0
activerecord/lib/active_record/connection_adapters/type/float.rb
...ecord/lib/active_record/connection_adapters/type/float.rb
+6
-0
activerecord/lib/active_record/connection_adapters/type/integer.rb
...ord/lib/active_record/connection_adapters/type/integer.rb
+6
-0
activerecord/lib/active_record/connection_adapters/type/string.rb
...cord/lib/active_record/connection_adapters/type/string.rb
+10
-0
activerecord/lib/active_record/connection_adapters/type/time.rb
...record/lib/active_record/connection_adapters/type/time.rb
+6
-0
activerecord/lib/active_record/connection_adapters/type/value.rb
...ecord/lib/active_record/connection_adapters/type/value.rb
+10
-0
activerecord/test/cases/column_test.rb
activerecord/test/cases/column_test.rb
+1
-1
未找到文件。
activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
浏览文件 @
36fde2b7
...
...
@@ -42,13 +42,21 @@ def sqlite3_connection(config)
module
ConnectionAdapters
#:nodoc:
class
SQLite3Column
<
Column
#:nodoc:
class
<<
self
def
binary_to_string
(
value
)
if
value
.
encoding
!=
Encoding
::
ASCII_8BIT
value
=
value
.
force_encoding
(
Encoding
::
ASCII_8BIT
)
end
value
def
type_cast
(
value
)
if
encoded?
super
else
cast_type
.
type_cast
(
value
)
end
end
end
class
SQLite3Binary
<
Type
::
Binary
# :nodoc:
def
cast_value
(
value
)
if
value
.
encoding
!=
Encoding
::
ASCII_8BIT
value
=
value
.
force_encoding
(
Encoding
::
ASCII_8BIT
)
end
value
end
end
...
...
@@ -502,6 +510,12 @@ def rename_column(table_name, column_name, new_column_name) #:nodoc:
end
protected
def
initialize_type_map
(
m
)
super
m
.
register_type
(
/binary/i
,
SQLite3Binary
.
new
)
end
def
select
(
sql
,
name
=
nil
,
binds
=
[])
#:nodoc:
exec_query
(
sql
,
name
,
binds
)
end
...
...
activerecord/lib/active_record/connection_adapters/type/boolean.rb
浏览文件 @
36fde2b7
...
...
@@ -5,6 +5,12 @@ class Boolean < Value # :nodoc:
def
type
:boolean
end
private
def
cast_value
(
value
)
Column
.
value_to_boolean
(
value
)
end
end
end
end
...
...
activerecord/lib/active_record/connection_adapters/type/date.rb
浏览文件 @
36fde2b7
...
...
@@ -5,6 +5,12 @@ class Date < Value # :nodoc:
def
type
:date
end
private
def
cast_value
(
value
)
Column
.
value_to_date
(
value
)
end
end
end
end
...
...
activerecord/lib/active_record/connection_adapters/type/date_time.rb
浏览文件 @
36fde2b7
...
...
@@ -5,6 +5,12 @@ class DateTime < Value # :nodoc:
def
type
:datetime
end
private
def
cast_value
(
string
)
Column
.
string_to_time
(
string
)
end
end
end
end
...
...
activerecord/lib/active_record/connection_adapters/type/decimal.rb
浏览文件 @
36fde2b7
...
...
@@ -5,6 +5,12 @@ class Decimal < Value # :nodoc:
def
type
:decimal
end
private
def
cast_value
(
value
)
Column
.
value_to_decimal
(
value
)
end
end
end
end
...
...
activerecord/lib/active_record/connection_adapters/type/float.rb
浏览文件 @
36fde2b7
...
...
@@ -5,6 +5,12 @@ class Float < Value # :nodoc:
def
type
:float
end
private
def
cast_value
(
value
)
value
.
to_f
end
end
end
end
...
...
activerecord/lib/active_record/connection_adapters/type/integer.rb
浏览文件 @
36fde2b7
...
...
@@ -5,6 +5,12 @@ class Integer < Value # :nodoc:
def
type
:integer
end
private
def
cast_value
(
value
)
Column
.
value_to_integer
(
value
)
end
end
end
end
...
...
activerecord/lib/active_record/connection_adapters/type/string.rb
浏览文件 @
36fde2b7
...
...
@@ -5,6 +5,16 @@ class String < Value # :nodoc:
def
type
:string
end
private
def
cast_value
(
value
)
case
value
when
true
then
"1"
when
false
then
"0"
else
value
.
to_s
end
end
end
end
end
...
...
activerecord/lib/active_record/connection_adapters/type/time.rb
浏览文件 @
36fde2b7
...
...
@@ -5,6 +5,12 @@ class Time < Value # :nodoc:
def
type
:time
end
private
def
cast_value
(
value
)
Column
.
string_to_dummy_time
(
value
)
end
end
end
end
...
...
activerecord/lib/active_record/connection_adapters/type/value.rb
浏览文件 @
36fde2b7
...
...
@@ -3,6 +3,16 @@ module ConnectionAdapters
module
Type
class
Value
# :nodoc:
def
type
;
end
def
type_cast
(
value
)
cast_value
(
value
)
unless
value
.
nil?
end
private
def
cast_value
(
value
)
value
end
end
end
end
...
...
activerecord/test/cases/column_test.rb
浏览文件 @
36fde2b7
...
...
@@ -146,7 +146,7 @@ def test_string_to_time_with_timezone
if
current_adapter?
(
:SQLite3Adapter
)
def
test_binary_encoding
column
=
SQLite3Column
.
new
(
"field"
,
nil
,
Type
::
Binary
.
new
)
column
=
SQLite3Column
.
new
(
"field"
,
nil
,
SQLite3
Binary
.
new
)
utf8_string
=
"a string"
.
encode
(
Encoding
::
UTF_8
)
type_cast
=
column
.
type_cast
(
utf8_string
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录