Skip to content

Commit

Permalink
add warning
Browse files Browse the repository at this point in the history
  • Loading branch information
crazycs520 committed Sep 17, 2019
1 parent df69702 commit c6069ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions expression/builtin_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,12 +626,13 @@ func (b *builtinTiDBDecodeKeySig) evalString(row chunk.Row) (string, bool, error
if isNull || err != nil {
return "", isNull, err
}
return decodeKey(s), false, nil
return decodeKey(b.ctx, s), false, nil
}

func decodeKey(s string) string {
func decodeKey(ctx sessionctx.Context, s string) string {
key, err := hex.DecodeString(s)
if err != nil {
ctx.GetSessionVars().StmtCtx.AppendWarning(errors.New("the key is a invalid record/index key"))
return s
}
// Auto decode byte if needs.
Expand All @@ -652,5 +653,6 @@ func decodeKey(s string) string {
}

// TODO: try to decode other type key.
ctx.GetSessionVars().StmtCtx.AppendWarning(errors.New("the key is a invalid record/index key"))
return s
}
7 changes: 7 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4131,6 +4131,13 @@ func (s *testIntegrationSuite) TestTiDBInternalFunc(c *C) {

result = tk.MustQuery("select tidb_decode_key( '74800000000000019B5F698000000000000001015257303100000000FB013736383232313130FF3900000000000000F8010000000000000000F7' )")
result.Check(testkit.Rows("tableID=411, indexID=1, indexValues=015257303100000000FB013736383232313130FF3900000000000000F8010000000000000000F7"))

// Test invalid record/index key.
result = tk.MustQuery("select tidb_decode_key( '7480000000000000FF2E5F728000000011FFE1A3000000000000' )")
result.Check(testkit.Rows("7480000000000000FF2E5F728000000011FFE1A3000000000000"))
warns := tk.Se.GetSessionVars().StmtCtx.GetWarnings()
c.Assert(warns, HasLen, 1)
c.Assert(warns[0].Err.Error(), Equals, "the key is a invalid record/index key")
}

func newStoreWithBootstrap() (kv.Storage, *domain.Domain, error) {
Expand Down

0 comments on commit c6069ff

Please sign in to comment.