Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2020fengziyang
soar
提交
b11fa0cd
S
soar
项目概览
2020fengziyang
/
soar
与 Fork 源项目一致
Fork自
Xiaomi / soar
通知
1
Star
1
Fork
0
代码
文件
提交
分支
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b11fa0cd
编写于
11月 17, 2018
作者:
martianzhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix #104
case insensitive regex @ CLA.009
上级
e5a73668
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
28 addition
and
14 deletion
+28
-14
advisor/heuristic.go
advisor/heuristic.go
+2
-2
advisor/heuristic_test.go
advisor/heuristic_test.go
+26
-12
未找到文件。
advisor/heuristic.go
浏览文件 @
b11fa0cd
...
@@ -629,8 +629,8 @@ func (q *Query4Audit) RuleOrderByExpr() Rule {
...
@@ -629,8 +629,8 @@ func (q *Query4Audit) RuleOrderByExpr() Rule {
var
rule
=
q
.
RuleOK
()
var
rule
=
q
.
RuleOK
()
var
orderByCols
[]
string
var
orderByCols
[]
string
var
selectCols
[]
string
var
selectCols
[]
string
funcExp
:=
regexp
.
MustCompile
(
`[a-z0-9]\(`
)
funcExp
:=
regexp
.
MustCompile
(
`
(?i)
[a-z0-9]\(`
)
allowExp
:=
regexp
.
MustCompile
(
"[a-z0-9_,.` ()]"
)
allowExp
:=
regexp
.
MustCompile
(
"
(?i)
[a-z0-9_,.` ()]"
)
err
:=
sqlparser
.
Walk
(
func
(
node
sqlparser
.
SQLNode
)
(
kontinue
bool
,
err
error
)
{
err
:=
sqlparser
.
Walk
(
func
(
node
sqlparser
.
SQLNode
)
(
kontinue
bool
,
err
error
)
{
switch
n
:=
node
.
(
type
)
{
switch
n
:=
node
.
(
type
)
{
case
sqlparser
.
OrderBy
:
case
sqlparser
.
OrderBy
:
...
...
advisor/heuristic_test.go
浏览文件 @
b11fa0cd
...
@@ -319,19 +319,22 @@ func TestRuleExplicitOrderBy(t *testing.T) {
...
@@ -319,19 +319,22 @@ func TestRuleExplicitOrderBy(t *testing.T) {
// CLA.009
// CLA.009
func
TestRuleOrderByExpr
(
t
*
testing
.
T
)
{
func
TestRuleOrderByExpr
(
t
*
testing
.
T
)
{
common
.
Log
.
Debug
(
"Entering function: %s"
,
common
.
GetFunctionName
())
common
.
Log
.
Debug
(
"Entering function: %s"
,
common
.
GetFunctionName
())
sqls
:=
[]
string
{
sqls
:=
[][]
string
{
{
"SELECT col FROM tbl order by cola - colb;"
,
// order by 列运算
"SELECT col FROM tbl order by cola - colb;"
,
// order by 列运算
"SELECT cola - colb col FROM tbl order by col;"
,
// 别名为列运算
"SELECT cola - colb col FROM tbl order by col;"
,
// 别名为列运算
"SELECT cola FROM tbl order by from_unixtime(col);"
,
// order by 函数运算
"SELECT cola FROM tbl order by from_unixtime(col);"
,
// order by 函数运算
"SELECT from_unixtime(col) cola FROM tbl order by cola;"
,
// 别名为函数运算
"SELECT from_unixtime(col) cola FROM tbl order by cola;"
,
// 别名为函数运算
},
// 反面例子
{
// `SELECT tbl.col FROM tbl ORDER BY col`,
`SELECT tbl.col FROM tbl ORDER BY col`
,
// "SELECT sum(col) AS col FROM tbl ORDER BY dt",
"SELECT sum(col) AS col FROM tbl ORDER BY dt"
,
// "SELECT tbl.col FROM tb, tbl WHERE tbl.tag_id = tb.id ORDER BY tbl.col",
"SELECT tbl.col FROM tb, tbl WHERE tbl.tag_id = tb.id ORDER BY tbl.col"
,
// "SELECT col FROM tbl order by `timestamp`;", // 列名为关键字
"SELECT col FROM tbl order by `timestamp`;"
,
// 列名为关键字
"select col from tb where cl = 1 order by APPLY_TIME"
,
// issue #104 case sensitive
},
}
}
for
_
,
sql
:=
range
sqls
{
for
_
,
sql
:=
range
sqls
[
0
]
{
q
,
err
:=
NewQuery4Audit
(
sql
)
q
,
err
:=
NewQuery4Audit
(
sql
)
if
err
==
nil
{
if
err
==
nil
{
rule
:=
q
.
RuleOrderByExpr
()
rule
:=
q
.
RuleOrderByExpr
()
...
@@ -342,6 +345,17 @@ func TestRuleOrderByExpr(t *testing.T) {
...
@@ -342,6 +345,17 @@ func TestRuleOrderByExpr(t *testing.T) {
t
.
Error
(
"sqlparser.Parse Error:"
,
err
)
t
.
Error
(
"sqlparser.Parse Error:"
,
err
)
}
}
}
}
for
_
,
sql
:=
range
sqls
[
1
]
{
q
,
err
:=
NewQuery4Audit
(
sql
)
if
err
==
nil
{
rule
:=
q
.
RuleOrderByExpr
()
if
rule
.
Item
!=
"OK"
{
t
.
Error
(
"Rule not match:"
,
rule
.
Item
,
"Expect : OK"
)
}
}
else
{
t
.
Error
(
"sqlparser.Parse Error:"
,
err
)
}
}
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录