Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
上島
soar
提交
6474f630
S
soar
项目概览
上島
/
soar
与 Fork 源项目一致
Fork自
Xiaomi / soar
通知
1
Star
0
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,发现更多精彩内容 >>
提交
6474f630
编写于
1月 15, 2020
作者:
martianzhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix SplitStatement cause endless loop bug
上级
4aa713f2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
14 addition
and
5 deletion
+14
-5
ast/token.go
ast/token.go
+1
-1
ast/token_test.go
ast/token_test.go
+5
-3
cmd/soar/soar.go
cmd/soar/soar.go
+8
-1
未找到文件。
ast/token.go
浏览文件 @
6474f630
...
...
@@ -851,7 +851,7 @@ func Compress(sql string) string {
}
// SplitStatement SQL切分
// return
original sql, remove comment sql,
left over buf
// return
1. original sql, 2. remove comment sql, 3.
left over buf
func
SplitStatement
(
buf
[]
byte
,
delimiter
[]
byte
)
(
string
,
string
,
[]
byte
)
{
var
singleLineComment
bool
var
multiLineComment
bool
...
...
ast/token_test.go
浏览文件 @
6474f630
...
...
@@ -172,6 +172,7 @@ select col from tb;
[]
byte
(
`select /*!50000 1,*/ 1;`
),
// 20
[]
byte
(
`UPDATE xxx SET c1=' LOGGER.error(""); }' WHERE id = 2 ;`
),
// 21
[]
byte
(
"UPDATE `xxx` SET aaa='a;' WHERE `id` = 15;"
),
// 22
// []byte(`/* comment here */ SET MAX_JOIN_SIZE=#`), // 23
}
// \G 分隔符
buf2s
:=
[][]
byte
{
...
...
@@ -185,9 +186,10 @@ select col from tb;
\\G*/
from test\\Ghello`
),
// 6
}
// single sql test
// SplitStatement(bufs[22], []byte(";"))
// return
//// single sql test
//b, t1, t2 := SplitStatement(bufs[23], []byte(";"))
//fmt.Println("buf: ", b, "sql: ", t1, "left: ", string(t2))
//return
err
:=
common
.
GoldenDiff
(
func
()
{
for
i
,
buf
:=
range
bufs
{
sql
,
_
,
_
:=
SplitStatement
(
buf
,
[]
byte
(
";"
))
...
...
cmd/soar/soar.go
浏览文件 @
6474f630
...
...
@@ -119,7 +119,14 @@ func main() {
// leftLineCounter
llc
:=
ast
.
LeftNewLines
([]
byte
(
orgSQL
))
lineCounter
+=
llc
buf
=
string
(
bufBytes
)
if
len
(
buf
)
==
len
(
bufBytes
)
{
// 防止切分死循环,当剩余的内容和原 SQL 相同时直接清空 buf
buf
=
""
orgSQL
=
string
(
bufBytes
)
sql
=
orgSQL
}
else
{
buf
=
string
(
bufBytes
)
}
// 去除无用的备注和空格
sql
=
database
.
RemoveSQLComments
(
sql
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录