Skip to content

Commit

Permalink
fix #112
Browse files Browse the repository at this point in the history
  multi-line comment will cause line counter error, when
  -report-type=lint
  • Loading branch information
martianzhang committed Nov 21, 2018
1 parent 6bb6a2e commit 8bb48a2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions ast/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions cmd/soar/soar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion database/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8bb48a2

Please sign in to comment.