Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
soar
提交
cd17cced
S
soar
项目概览
Xiaomi
/
soar
大约 2 年 前同步成功
通知
467
Star
8513
Fork
1329
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
soar
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
cd17cced
编写于
10月 08, 2019
作者:
martianzhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix #229
SELECT c1, c2, c3, FROM tb WHERE id < 1000 AND content="mytest* as test"
上级
f818c326
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
22 addition
and
6 deletion
+22
-6
advisor/heuristic.go
advisor/heuristic.go
+5
-3
advisor/heuristic_test.go
advisor/heuristic_test.go
+17
-3
未找到文件。
advisor/heuristic.go
浏览文件 @
cd17cced
...
@@ -64,9 +64,11 @@ func (q *Query4Audit) RuleImplicitAlias() Rule {
...
@@ -64,9 +64,11 @@ func (q *Query4Audit) RuleImplicitAlias() Rule {
// RuleStarAlias ALI.002
// RuleStarAlias ALI.002
func
(
q
*
Query4Audit
)
RuleStarAlias
()
Rule
{
func
(
q
*
Query4Audit
)
RuleStarAlias
()
Rule
{
var
rule
=
q
.
RuleOK
()
var
rule
=
q
.
RuleOK
()
re
:=
regexp
.
MustCompile
(
`(?i)(\*\s+as\b)`
)
tkns
:=
ast
.
Tokenizer
(
q
.
Query
)
if
re
.
FindString
(
q
.
Query
)
!=
""
{
for
i
,
tkn
:=
range
tkns
{
rule
=
HeuristicRules
[
"ALI.002"
]
if
tkn
.
Val
==
"*"
&&
i
+
1
<
len
(
tkns
)
&&
tkns
[
i
+
1
]
.
Val
==
"as"
{
rule
=
HeuristicRules
[
"ALI.002"
]
}
}
}
return
rule
return
rule
}
}
...
...
advisor/heuristic_test.go
浏览文件 @
cd17cced
...
@@ -60,16 +60,30 @@ func TestRuleImplicitAlias(t *testing.T) {
...
@@ -60,16 +60,30 @@ func TestRuleImplicitAlias(t *testing.T) {
// ALI.002
// ALI.002
func
TestRuleStarAlias
(
t
*
testing
.
T
)
{
func
TestRuleStarAlias
(
t
*
testing
.
T
)
{
common
.
Log
.
Debug
(
"Entering function: %s"
,
common
.
GetFunctionName
())
common
.
Log
.
Debug
(
"Entering function: %s"
,
common
.
GetFunctionName
())
sqls
:=
[]
string
{
sqls
:=
[][]
string
{
"select tbl.* as c1,c2,c3 from tbl where id < 1000"
,
{
"select tbl.* AS c1,c2,c3 from tbl where id < 1000"
,
"SELECT * as"
,
},
{
`SELECT c1, c2, c3, FROM tb WHERE id < 1000 AND content="mytest* as test"`
,
`select *`
,
},
}
}
for
_
,
sql
:=
range
sqls
{
for
_
,
sql
:=
range
sqls
[
0
]
{
q
,
_
:=
NewQuery4Audit
(
sql
)
q
,
_
:=
NewQuery4Audit
(
sql
)
rule
:=
q
.
RuleStarAlias
()
rule
:=
q
.
RuleStarAlias
()
if
rule
.
Item
!=
"ALI.002"
{
if
rule
.
Item
!=
"ALI.002"
{
t
.
Error
(
"Rule not match:"
,
rule
.
Item
,
"Expect : ALI.002"
)
t
.
Error
(
"Rule not match:"
,
rule
.
Item
,
"Expect : ALI.002"
)
}
}
}
}
for
_
,
sql
:=
range
sqls
[
1
]
{
q
,
_
:=
NewQuery4Audit
(
sql
)
rule
:=
q
.
RuleStarAlias
()
if
rule
.
Item
!=
"OK"
{
t
.
Error
(
"Rule not match:"
,
rule
.
Item
,
"Expect : OK"
)
}
}
common
.
Log
.
Debug
(
"Exiting function: %s"
,
common
.
GetFunctionName
())
common
.
Log
.
Debug
(
"Exiting function: %s"
,
common
.
GetFunctionName
())
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录