Skip to content

server: replace instead of truncate encoded result (#61080) #61193

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions cmd/explaintest/r/new_character_set.result
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,14 @@ set @@character_set_connection=gbk;
select hex('一a'), '一a';
hex('涓?') 涓?
E4B83F 涓?
set character_set_results = "gbk";
select cast(0x414141E280A9424242 as char charset utf8mb4);
cast(0x414141E280A9424242 as char charset utf8mb4)
AAA?BBB
SET character_set_results = @undefined_var;
create table t61085 (a char(255) charset gbk);
insert into t61085 values ('AAA');
set SESSION sql_mode = '';
select * from t61085 where a = cast(0x41414180424242 as char charset gbk);
Error 1105 (HY000): Cannot convert string 'AAA\x80BB...' from binary to gbk
DROP TABLE t61085;
11 changes: 11 additions & 0 deletions cmd/explaintest/t/new_character_set.test
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,14 @@ set names utf8mb4;
set @@character_set_client=gbk;
set @@character_set_connection=gbk;
select hex('一a'), '一a';

-- Bug#61085: https://github.com/pingcap/tidb/issues/61085 should replace instead of truncation for result charset
set character_set_results = "gbk";
select cast(0x414141E280A9424242 as char charset utf8mb4);
SET character_set_results = @undefined_var;
create table t61085 (a char(255) charset gbk);
insert into t61085 values ('AAA');
set SESSION sql_mode = '';
--error 1105
select * from t61085 where a = cast(0x41414180424242 as char charset gbk);
DROP TABLE t61085;
2 changes: 1 addition & 1 deletion server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func (d *resultEncoder) encodeData(src []byte) []byte {
}

func (d *resultEncoder) encodeWith(src []byte, enc charset.Encoding) []byte {
data, err := enc.Transform(d.buffer, src, charset.OpEncode)
data, err := enc.Transform(d.buffer, src, charset.OpEncodeReplace)
if err != nil {
logutil.BgLogger().Debug("encode error", zap.Error(err))
}
Expand Down