Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
soar
提交
d22add80
S
soar
项目概览
Xiaomi
/
soar
大约 1 年 前同步成功
通知
387
Star
8512
Fork
1328
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
d22add80
编写于
2月 20, 2019
作者:
martianzhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
-report-type query-type add syntax check
上级
471e0d35
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
10 addition
and
6 deletion
+10
-6
ast/testdata/TestQueryType.golden
ast/testdata/TestQueryType.golden
+1
-0
ast/token.go
ast/token.go
+1
-1
ast/token_test.go
ast/token_test.go
+1
-0
cmd/soar/soar.go
cmd/soar/soar.go
+7
-5
未找到文件。
ast/testdata/TestQueryType.golden
浏览文件 @
d22add80
SELECT
SELECT
SELECT
SELECT
SELECT
GRANT
GRANT
REVOKE
REVOKE
SELECT
SELECT
...
...
ast/token.go
浏览文件 @
d22add80
...
@@ -1000,5 +1000,5 @@ func QueryType(sql string) string {
...
@@ -1000,5 +1000,5 @@ func QueryType(sql string) string {
}
}
}
}
}
}
return
""
return
"
UNKNOWN
"
}
}
ast/token_test.go
浏览文件 @
d22add80
...
@@ -241,6 +241,7 @@ func TestNewLines(t *testing.T) {
...
@@ -241,6 +241,7 @@ func TestNewLines(t *testing.T) {
func
TestQueryType
(
t
*
testing
.
T
)
{
func
TestQueryType
(
t
*
testing
.
T
)
{
common
.
Log
.
Debug
(
"Entering function: %s"
,
common
.
GetFunctionName
())
common
.
Log
.
Debug
(
"Entering function: %s"
,
common
.
GetFunctionName
())
var
testSQLs
=
[]
string
{
var
testSQLs
=
[]
string
{
` select 1`
,
`/*comment*/ select 1`
,
`/*comment*/ select 1`
,
`(select 1)`
,
`(select 1)`
,
`grant select on *.* to user@'localhost'`
,
`grant select on *.* to user@'localhost'`
,
...
...
cmd/soar/soar.go
浏览文件 @
d22add80
...
@@ -163,10 +163,6 @@ func main() {
...
@@ -163,10 +163,6 @@ func main() {
_
,
err
=
pretty
.
Println
(
ast
.
Tokenize
(
sql
))
_
,
err
=
pretty
.
Println
(
ast
.
Tokenize
(
sql
))
common
.
LogIfWarn
(
err
,
""
)
common
.
LogIfWarn
(
err
,
""
)
continue
continue
case
"query-type"
:
// query type by first key word
fmt
.
Println
(
ast
.
QueryType
(
sql
))
continue
default
:
default
:
// SQL 签名
// SQL 签名
id
=
query
.
Id
(
fingerprint
)
id
=
query
.
Id
(
fingerprint
)
...
@@ -190,7 +186,8 @@ func main() {
...
@@ -190,7 +186,8 @@ func main() {
if
syntaxErr
!=
nil
{
if
syntaxErr
!=
nil
{
errContent
:=
fmt
.
Sprintf
(
"At SQL %d : %v"
,
sqlCounter
,
syntaxErr
)
errContent
:=
fmt
.
Sprintf
(
"At SQL %d : %v"
,
sqlCounter
,
syntaxErr
)
common
.
Log
.
Warning
(
errContent
)
common
.
Log
.
Warning
(
errContent
)
if
common
.
Config
.
OnlySyntaxCheck
||
common
.
Config
.
ReportType
==
"rewrite"
{
if
common
.
Config
.
OnlySyntaxCheck
||
common
.
Config
.
ReportType
==
"rewrite"
||
common
.
Config
.
ReportType
==
"query-type"
{
fmt
.
Println
(
errContent
)
fmt
.
Println
(
errContent
)
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
...
@@ -208,6 +205,11 @@ func main() {
...
@@ -208,6 +205,11 @@ func main() {
env
.
ChangeDB
(
vEnv
.
Connector
,
q
.
Query
)
env
.
ChangeDB
(
vEnv
.
Connector
,
q
.
Query
)
tables
[
id
]
=
ast
.
SchemaMetaInfo
(
sql
,
vEnv
.
Database
)
tables
[
id
]
=
ast
.
SchemaMetaInfo
(
sql
,
vEnv
.
Database
)
continue
continue
case
"query-type"
:
fmt
.
Println
(
syntaxErr
)
// query type by first key word
fmt
.
Println
(
ast
.
QueryType
(
sql
))
continue
}
}
// +++++++++++++++++++++启发式规则建议[开始]+++++++++++++++++++++++{
// +++++++++++++++++++++启发式规则建议[开始]+++++++++++++++++++++++{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录