Skip to content

Commit

Permalink
bindinfo: fix the bind fields with quotes or slashes (#11671)
Browse files Browse the repository at this point in the history
  • Loading branch information
zimulala authored and zz-jason committed Aug 13, 2019
1 parent 922f569 commit 2cfdd9e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
5 changes: 5 additions & 0 deletions bindinfo/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ func (s *testSuite) TestBindParse(c *C) {
c.Check(bindData.Collation, Equals, "utf8mb4_bin")
c.Check(bindData.CreateTime, NotNil)
c.Check(bindData.UpdateTime, NotNil)

// Test fields with quotes or slashes.
sql = `CREATE GLOBAL BINDING FOR select * from t where a BETWEEN "a" and "b" USING select * from t use index(idx) where a BETWEEN "a\nb\rc\td\0e" and "x"`
tk.MustExec(sql)
tk.MustExec(`DROP global binding for select * from t use index(idx) where a BETWEEN "a\nb\rc\td\0e" and "x"`)
}

func (s *testSuite) TestGlobalBinding(c *C) {
Expand Down
13 changes: 0 additions & 13 deletions bindinfo/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package bindinfo

import (
"bytes"
"context"
"fmt"
"go.uber.org/zap"
Expand Down Expand Up @@ -188,7 +187,6 @@ func (h *BindHandle) AddBindRecord(record *BindRecord) (err error) {
}
record.UpdateTime = record.CreateTime
record.Status = Using
record.BindSQL = h.getEscapeCharacter(record.BindSQL)

// insert the BindRecord to the storage.
_, err = exec.Execute(context.TODO(), h.insertBindInfoSQL(record))
Expand Down Expand Up @@ -446,14 +444,3 @@ func (h *BindHandle) logicalDeleteBindInfoSQL(normdOrigSQL, db string, updateTs
normdOrigSQL,
db)
}

func (h *BindHandle) getEscapeCharacter(str string) string {
var buffer bytes.Buffer
for _, v := range str {
if v == '\'' || v == '"' || v == '\\' {
buffer.WriteString("\\")
}
buffer.WriteString(string(v))
}
return buffer.String()
}

0 comments on commit 2cfdd9e

Please sign in to comment.