Skip to content

Commit

Permalink
use util.Fingerprint to fix panic ce
Browse files Browse the repository at this point in the history
  • Loading branch information
BugsGuru committed Oct 29, 2024
1 parent f2d33a5 commit 006be20
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 9 additions & 0 deletions sqle/driver/mysql/util/parser_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ func TestFingerprint(t *testing.T) {
input: "select * from tb1 where a='my_db' and b='test1'# this is a comment",
expect: "SELECT * FROM `tb1` WHERE `a`=? AND `b`=?",
},
// not sql
{
input: "SELECT*FROM (SELECT * FROM tb values(1));",
expect: "SELECT*FROM (SELECT * FROM tb values(1));",
},
{
input: "not sql",
expect: "not sql",
},
}
for _, c := range cases {
testFingerprint(t, c.input, c.expect)
Expand Down
8 changes: 6 additions & 2 deletions sqle/pkg/driver/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"fmt"
"time"

"github.com/actiontech/sqle/sqle/driver/mysql/util"
driverV2 "github.com/actiontech/sqle/sqle/driver/v2"
"github.com/actiontech/sqle/sqle/pkg/params"
"github.com/actiontech/sqle/sqle/utils"
hclog "github.com/hashicorp/go-hclog"

"github.com/percona/go-mysql/query"
"github.com/pkg/errors"
"vitess.io/vitess/go/vt/sqlparser"
)
Expand Down Expand Up @@ -200,10 +200,14 @@ func (p *DriverImpl) Parse(ctx context.Context, sql string) ([]driverV2.Node, er

nodes := make([]driverV2.Node, 0, len(sqls))
for _, sql := range sqls {
fp, err := util.Fingerprint(sql, true)
if err != nil {
return nil, errors.Wrapf(err, "fingerprint of sql: %s", sql)
}
n := driverV2.Node{
Text: sql,
Type: classifySQL(sql),
Fingerprint: query.Fingerprint(sql),
Fingerprint: fp,
}
nodes = append(nodes, n)
}
Expand Down

0 comments on commit 006be20

Please sign in to comment.