提交 8bb48a29 编写于 作者: martianzhang's avatar martianzhang

fix #112

  multi-line comment will cause line counter error, when
  -report-type=lint
上级 6bb6a2e1
......@@ -894,7 +894,8 @@ func Compress(sql string) string {
}
// SplitStatement SQL切分
func SplitStatement(buf []byte, delimiter []byte) (string, []byte) {
// return original sql, remove comment sql, left over buf
func SplitStatement(buf []byte, delimiter []byte) (string, string, []byte) {
var singleLineComment bool
var multiLineComment bool
var quoted bool
......@@ -988,8 +989,9 @@ func SplitStatement(buf []byte, delimiter []byte) (string, []byte) {
sql = string(buf)
}
}
orgSQL := string(buf[:len(sql)])
buf = buf[len(sql):]
return strings.TrimSuffix(sql, string(delimiter)), buf
return orgSQL, strings.TrimSuffix(sql, string(delimiter)), buf
}
// LeftNewLines cal left new lines in space
......
......@@ -111,11 +111,11 @@ func main() {
break
}
// 查询请求切分
sql, bufBytes := ast.SplitStatement([]byte(buf), []byte(common.Config.Delimiter))
orgSQL, sql, bufBytes := ast.SplitStatement([]byte(buf), []byte(common.Config.Delimiter))
// lineCounter
lc := ast.NewLines([]byte(sql))
lc := ast.NewLines([]byte(orgSQL))
// leftLineCounter
llc := ast.LeftNewLines([]byte(sql))
llc := ast.LeftNewLines([]byte(orgSQL))
lineCounter += llc
buf = string(bufBytes)
......
......@@ -170,7 +170,7 @@ func (db *Connector) Source(file string) ([]*QueryResult, error) {
}
// 查询请求切分
sql, bufBytes := ast.SplitStatement([]byte(buf), []byte(common.Config.Delimiter))
_, sql, bufBytes := ast.SplitStatement([]byte(buf), []byte(common.Config.Delimiter))
buf = string(bufBytes)
sql = strings.TrimSpace(sql)
common.Log.Debug("Source Query SQL: %s", sql)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册