Skip to content

Commit ac2c9a6

Browse files
committed
Better error message for bad string for charset
1 parent a5fe3d6 commit ac2c9a6

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

enginetest/enginetests.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4314,14 +4314,14 @@ func TestPreparedInsert(t *testing.T, harness Harness) {
43144314
Bindings: map[string]sqlparser.Expr{
43154315
"v1": mustBuildBindVariable([]byte{0x99, 0x98, 0x97}),
43164316
},
4317-
ExpectedErrStr: "incorrect string value: '[153 152 151]'",
4317+
ExpectedErrStr: "invalid string for charset utf8mb4: '[153 152 151]'",
43184318
},
43194319
{
43204320
Query: "INSERT INTO test VALUES (?);",
43214321
Bindings: map[string]sqlparser.Expr{
43224322
"v1": mustBuildBindVariable(string([]byte{0x99, 0x98, 0x97})),
43234323
},
4324-
ExpectedErrStr: "incorrect string value: '[153 152 151]'",
4324+
ExpectedErrStr: "invalid string for charset utf8mb4: '[153 152 151]'",
43254325
},
43264326
{
43274327
Query: "INSERT INTO test2 VALUES (?);",

enginetest/queries/script_queries.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7135,15 +7135,15 @@ where
71357135
Assertions: []ScriptTestAssertion{
71367136
{
71377137
Query: "insert into t(c) values (X'9876543210');",
7138-
ExpectedErrStr: "incorrect string value: '[152 118 84 50 16]'",
7138+
ExpectedErrStr: "invalid string for charset utf8mb4: '[152 118 84 50 16]'",
71397139
},
71407140
{
71417141
Query: "insert into t(v) values (X'9876543210');",
7142-
ExpectedErrStr: "incorrect string value: '[152 118 84 50 16]'",
7142+
ExpectedErrStr: "invalid string for charset utf8mb4: '[152 118 84 50 16]'",
71437143
},
71447144
{
71457145
Query: "insert into t(txt) values (X'9876543210');",
7146-
ExpectedErrStr: "incorrect string value: '[152 118 84 50 16]'",
7146+
ExpectedErrStr: "invalid string for charset utf8mb4: '[152 118 84 50 16]'",
71477147
},
71487148
{
71497149
Query: "insert into t(b) values (X'9876543210');",

sql/types/strings.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ var (
4848
ErrLengthTooLarge = errors.NewKind("length is %v but max allowed is %v")
4949
ErrLengthBeyondLimit = errors.NewKind("string '%v' is too large for column '%v'")
5050
ErrBinaryCollation = errors.NewKind("binary types must have the binary collation: %v")
51-
ErrIncorrectStringValue = errors.NewKind("incorrect string value: '%v'")
51+
ErrBadCharsetString = errors.NewKind("invalid string for charset %s: '%v'")
5252

5353
TinyText = MustCreateStringWithDefaults(sqltypes.Text, TinyTextBlobMax)
5454
Text = MustCreateStringWithDefaults(sqltypes.Text, TextBlobMax)
@@ -428,11 +428,11 @@ func ConvertToString(v interface{}, t sql.StringType) (string, error) {
428428
if !IsBinaryType(t) && !utf8.Valid(bytesVal) {
429429
charset := t.CharacterSet()
430430
if charset == sql.CharacterSet_utf8mb4 {
431-
return "", ErrIncorrectStringValue.New(bytesVal)
431+
return "", ErrBadCharsetString.New(charset.String(), bytesVal)
432432
} else {
433433
var ok bool
434434
if bytesVal, ok = t.CharacterSet().Encoder().Decode(bytesVal); !ok {
435-
return "", ErrIncorrectStringValue.New(bytesVal)
435+
return "", ErrBadCharsetString.New(charset.String(), bytesVal)
436436
}
437437
}
438438
}

0 commit comments

Comments
 (0)