Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: print non-printable chars in hex style for duplicate entry error #39485

Merged
merged 38 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
03ce121
session: remove useless parser object in SessionHandle of bindinfo pa…
winkyao Nov 28, 2022
4305e94
Merge branch 'master' into master
winkyao Nov 28, 2022
68eecc2
session: change parser.New to get a parser from pool
winkyao Nov 29, 2022
9bf7765
Merge branch 'master' of github.com:winkyao/tidb
winkyao Nov 29, 2022
829a337
Revert "session: change parser.New to get a parser from pool"
winkyao Nov 29, 2022
a8dfda7
Merge branch 'master' into master
crazycs520 Nov 29, 2022
9dad1ba
Merge branch 'master' into master
ti-chi-bot Nov 29, 2022
170ed4c
session: change parser.New to get a parser from pool
winkyao Nov 29, 2022
e76538f
Revert "session: change parser.New to get a parser from pool"
winkyao Nov 29, 2022
5a58471
error: fix #35289, turn non-printable chars in Duplicate entry error …
winkyao Nov 30, 2022
a487c12
Merge remote-tracking branch 'upstream/master'
winkyao Nov 30, 2022
9cec937
add unit test
winkyao Nov 30, 2022
d4101fb
Merge branch 'master' of github.com:winkyao/tidb
winkyao Nov 30, 2022
a1f0789
tidy the imports
winkyao Nov 30, 2022
70bacbb
adressed comment
winkyao Nov 30, 2022
db4e92d
addressed comments and fix the dup error msg in adding unique index
winkyao Nov 30, 2022
5608e01
Merge branch 'master' into master
winkyao Nov 30, 2022
dc6f191
fix test result
winkyao Nov 30, 2022
e57d034
fix import
winkyao Nov 30, 2022
39f4c5b
Merge branch 'master' into master
winkyao Dec 1, 2022
905ea22
fix bazel
winkyao Dec 1, 2022
b923cfb
Merge branch 'master' of github.com:winkyao/tidb
winkyao Dec 1, 2022
e1c8bbb
Merge branch 'master' into master
winkyao Dec 1, 2022
aa406ed
Merge branch 'master' into master
crazycs520 Dec 1, 2022
9a14ebe
Merge branch 'master' into master
hawkingrei Dec 1, 2022
6fa18f0
Merge branch 'master' into master
ti-chi-bot Dec 1, 2022
42e9d40
Merge branch 'master' into master
hawkingrei Dec 1, 2022
ec13fc6
Merge branch 'master' into master
ti-chi-bot Dec 1, 2022
2937316
Merge branch 'master' into master
ti-chi-bot Dec 1, 2022
03bd56c
Merge branch 'master' into master
ti-chi-bot Dec 1, 2022
24609c7
Merge branch 'master' into master
ti-chi-bot Dec 1, 2022
35b153f
Merge branch 'master' into master
ti-chi-bot Dec 1, 2022
4130d5d
Merge branch 'master' into master
ti-chi-bot Dec 1, 2022
20c74d1
Merge branch 'master' into master
ti-chi-bot Dec 1, 2022
55aab9e
Merge branch 'master' into master
ti-chi-bot Dec 1, 2022
344138c
Merge branch 'master' into master
ti-chi-bot Dec 1, 2022
254d1af
Merge branch 'master' into master
ti-chi-bot Dec 1, 2022
1824ffa
Merge branch 'master' into master
crazycs520 Dec 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7895,3 +7895,17 @@ func TestIssue39146(t *testing.T) {
tk.MustExec("set @@tidb_enable_vectorized_expression = off;")
tk.MustQuery(`select str_to_date(substr(dest,1,6),'%H%i%s') from sun;`).Check(testkit.Rows("20:23:10"))
}

func TestIssue35289(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestIssue35289 is a bad name of test cases. we should avoid it.

I think it is a corner case about insert and we can put it into TestInsert and comment the issue id.

store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("CREATE TABLE t1 (a BINARY(16) PRIMARY KEY);")
tk.MustExec(`INSERT INTO t1 VALUES (AES_ENCRYPT('a','a'));`)
err := tk.ExecToErr(`INSERT INTO t1 VALUES (AES_ENCRYPT('a','a'));`)
require.Error(t, err, `ERROR 1062 (23000): Duplicate entry '{ W]\xA1\x06u\x9D\xBD\xB1\xA3.\xE2\xD9\xA7t' for key 't1.PRIMARY'`)

tk.MustExec(`INSERT INTO t1 VALUES (AES_ENCRYPT('b','b'));`)
err = tk.ExecToErr(`INSERT INTO t1 VALUES (AES_ENCRYPT('b','b'));`)
require.Error(t, err, "ERROR 1062 (23000): Duplicate entry '\x0C\x1E\x8DG`\xEB\x93 F&BC\xF0\xB5\xF4\xB7' for key 't1.PRIMARY'")
}
28 changes: 28 additions & 0 deletions store/driver/txn/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,31 @@ func genKeyExistsError(name string, value string, err error) error {
return kv.ErrKeyExists.FastGenByArgs(value, name)
}

func printableASCII(b byte) bool {
if b >= 0 && b < 32 || b > 127 {
return false
}

return true
}

// fmtNonASCIIPrintableCharToHex turns non-printable-ASCII characters into Hex
func fmtNonASCIIPrintableCharToHex(str string) string {
var b bytes.Buffer
b.Grow(len(str) * 2)
for i := 0; i < len(str); i++ {
if printableASCII(str[i]) {
b.WriteByte(str[i])
continue
}

b.WriteString(`\x`)
// turns non-printable-ASCII character into hex-string
b.WriteString(fmt.Sprintf("%02X", str[i]))
}
return b.String()
}

func extractKeyExistsErrFromHandle(key kv.Key, value []byte, tblInfo *model.TableInfo) error {
name := tblInfo.Name.String() + ".PRIMARY"
_, handle, err := tablecodec.DecodeRecordKey(key)
Expand Down Expand Up @@ -100,6 +125,8 @@ func extractKeyExistsErrFromHandle(key kv.Key, value []byte, tblInfo *model.Tabl
if col.Length > 0 && len(str) > col.Length {
str = str[:col.Length]
}

str = fmtNonASCIIPrintableCharToHex(str)
tangenta marked this conversation as resolved.
Show resolved Hide resolved
valueStr = append(valueStr, str)
}
return genKeyExistsError(name, strings.Join(valueStr, "-"), nil)
Expand Down Expand Up @@ -136,6 +163,7 @@ func extractKeyExistsErrFromIndex(key kv.Key, value []byte, tblInfo *model.Table
if err != nil {
return genKeyExistsError(name, key.String(), err)
}
str = fmtNonASCIIPrintableCharToHex(str)
valueStr = append(valueStr, str)
}
return genKeyExistsError(name, strings.Join(valueStr, "-"), nil)
Expand Down