Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
ede507d6
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,发现更多精彩内容 >>
提交
ede507d6
编写于
5月 10, 2011
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #51 from square/thread-safety
Make ToSql more thread safe.
上级
a3d9c393
73ca3932
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
21 addition
and
5 deletion
+21
-5
lib/arel/visitors/to_sql.rb
lib/arel/visitors/to_sql.rb
+4
-5
test/visitors/test_to_sql.rb
test/visitors/test_to_sql.rb
+17
-0
未找到文件。
lib/arel/visitors/to_sql.rb
浏览文件 @
ede507d6
...
...
@@ -8,14 +8,13 @@ def initialize engine
@engine
=
engine
@connection
=
nil
@pool
=
nil
@last_column
=
nil
@quoted_tables
=
{}
@quoted_columns
=
{}
end
def
accept
object
@last_column
=
nil
@pool
=
@engine
.
connection_pool
Thread
.
current
[
:arel_visitors_to_sql_last_column
]
=
nil
@pool
=
@engine
.
connection_pool
@pool
.
with_connection
do
|
conn
|
@connection
=
conn
super
...
...
@@ -356,7 +355,7 @@ def visit_Arel_Nodes_UnqualifiedColumn o
end
def
visit_Arel_Attributes_Attribute
o
@last_column
=
column_for
o
Thread
.
current
[
:arel_visitors_to_sql_last_column
]
=
column_for
o
join_name
=
o
.
relation
.
table_alias
||
o
.
relation
.
name
"
#{
quote_table_name
join_name
}
.
#{
quote_column_name
o
.
name
}
"
end
...
...
@@ -374,7 +373,7 @@ def literal o; o end
alias
:visit_Bignum
:literal
alias
:visit_Fixnum
:literal
def
quoted
o
;
quote
(
o
,
@last_column
)
end
def
quoted
o
;
quote
(
o
,
Thread
.
current
[
:arel_visitors_to_sql_last_column
]
)
end
alias
:visit_ActiveSupport_Multibyte_Chars
:quoted
alias
:visit_ActiveSupport_StringInquirer
:quoted
...
...
test/visitors/test_to_sql.rb
浏览文件 @
ede507d6
require
'helper'
class
Arel::Visitors::ToSql
def
last_column
;
Thread
.
current
[
:arel_visitors_to_sql_last_column
]
||
@last_column
;
end
end
module
Arel
module
Visitors
describe
'the to_sql visitor'
do
...
...
@@ -9,6 +13,19 @@ module Visitors
@attr
=
@table
[
:id
]
end
it
"should be thread safe around usage of last_column"
do
visit_integer_column
=
Thread
.
new
do
Thread
.
stop
@visitor
.
send
(
:visit_Arel_Attributes_Attribute
,
@attr
)
end
@visitor
.
accept
(
@table
[
:name
])
assert_equal
(
:string
,
@visitor
.
last_column
.
type
)
visit_integer_column
.
run
visit_integer_column
.
join
assert_equal
(
:string
,
@visitor
.
last_column
.
type
)
end
it
'should not quote sql literals'
do
node
=
@table
[
Arel
.
star
]
sql
=
@visitor
.
accept
node
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录