Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
e8aa045d
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,发现更多精彩内容 >>
提交
e8aa045d
编写于
2月 05, 2014
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #243 from vanderhoorn/patch-1
PostgreSQL bugfix for invalid SQL in subqueries
上级
f0ba9e4e
557a8769
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
72 addition
and
0 deletion
+72
-0
lib/arel/visitors/postgresql.rb
lib/arel/visitors/postgresql.rb
+2
-0
test/visitors/test_postgres.rb
test/visitors/test_postgres.rb
+36
-0
test/visitors/test_to_sql.rb
test/visitors/test_to_sql.rb
+34
-0
未找到文件。
lib/arel/visitors/postgresql.rb
浏览文件 @
e8aa045d
...
...
@@ -4,10 +4,12 @@ class PostgreSQL < Arel::Visitors::ToSql
private
def
visit_Arel_Nodes_Matches
o
,
a
a
=
o
.
left
if
Arel
::
Attributes
::
Attribute
===
o
.
left
"
#{
visit
o
.
left
,
a
}
ILIKE
#{
visit
o
.
right
,
a
}
"
end
def
visit_Arel_Nodes_DoesNotMatch
o
,
a
a
=
o
.
left
if
Arel
::
Attributes
::
Attribute
===
o
.
left
"
#{
visit
o
.
left
,
a
}
NOT ILIKE
#{
visit
o
.
right
,
a
}
"
end
...
...
test/visitors/test_postgres.rb
浏览文件 @
e8aa045d
...
...
@@ -5,6 +5,8 @@ module Visitors
describe
'the postgres visitor'
do
before
do
@visitor
=
PostgreSQL
.
new
Table
.
engine
.
connection
@table
=
Table
.
new
(
:users
)
@attr
=
@table
[
:id
]
end
describe
'locking'
do
...
...
@@ -43,6 +45,40 @@ module Visitors
core
.
set_quantifier
=
Arel
::
Nodes
::
Distinct
.
new
assert_equal
'SELECT DISTINCT'
,
@visitor
.
accept
(
core
)
end
describe
"Nodes::Matches"
do
it
"should know how to visit"
do
node
=
@table
[
:name
].
matches
(
'foo%'
)
@visitor
.
accept
(
node
).
must_be_like
%{
"users"."name" ILIKE 'foo%'
}
end
it
'can handle subqueries'
do
subquery
=
@table
.
project
(
:id
).
where
(
@table
[
:name
].
matches
(
'foo%'
))
node
=
@attr
.
in
subquery
@visitor
.
accept
(
node
).
must_be_like
%{
"users"."id" IN (SELECT id FROM "users" WHERE "users"."name" ILIKE 'foo%')
}
end
end
describe
"Nodes::DoesNotMatch"
do
it
"should know how to visit"
do
node
=
@table
[
:name
].
does_not_match
(
'foo%'
)
@visitor
.
accept
(
node
).
must_be_like
%{
"users"."name" NOT ILIKE 'foo%'
}
end
it
'can handle subqueries'
do
subquery
=
@table
.
project
(
:id
).
where
(
@table
[
:name
].
does_not_match
(
'foo%'
))
node
=
@attr
.
in
subquery
@visitor
.
accept
(
node
).
must_be_like
%{
"users"."id" IN (SELECT id FROM "users" WHERE "users"."name" NOT ILIKE 'foo%')
}
end
end
end
end
end
test/visitors/test_to_sql.rb
浏览文件 @
e8aa045d
...
...
@@ -194,6 +194,40 @@ def dispatch
@visitor
.
accept
(
test
).
must_be_like
%{ "users"."bool" = 't' }
end
describe
"Nodes::Matches"
do
it
"should know how to visit"
do
node
=
@table
[
:name
].
matches
(
'foo%'
)
@visitor
.
accept
(
node
).
must_be_like
%{
"users"."name" LIKE 'foo%'
}
end
it
'can handle subqueries'
do
subquery
=
@table
.
project
(
:id
).
where
(
@table
[
:name
].
matches
(
'foo%'
))
node
=
@attr
.
in
subquery
@visitor
.
accept
(
node
).
must_be_like
%{
"users"."id" IN (SELECT id FROM "users" WHERE "users"."name" LIKE 'foo%')
}
end
end
describe
"Nodes::DoesNotMatch"
do
it
"should know how to visit"
do
node
=
@table
[
:name
].
does_not_match
(
'foo%'
)
@visitor
.
accept
(
node
).
must_be_like
%{
"users"."name" NOT LIKE 'foo%'
}
end
it
'can handle subqueries'
do
subquery
=
@table
.
project
(
:id
).
where
(
@table
[
:name
].
does_not_match
(
'foo%'
))
node
=
@attr
.
in
subquery
@visitor
.
accept
(
node
).
must_be_like
%{
"users"."id" IN (SELECT id FROM "users" WHERE "users"."name" NOT LIKE 'foo%')
}
end
end
describe
"Nodes::Ordering"
do
it
"should know how to visit"
do
node
=
@attr
.
desc
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录