Skip to content

Commit

Permalink
remove flag
Browse files Browse the repository at this point in the history
Signed-off-by: xiongjiwei <xiongjiwei1996@outlook.com>
  • Loading branch information
xiongjiwei committed Sep 1, 2022
1 parent a04000c commit 53b0c30
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ddl/column_type_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ func TestColumnTypeChangeFromStringToOthers(t *testing.T) {
tk.MustExec("alter table t modify txt json")
tk.MustExec("alter table t modify e json")
tk.MustExec("alter table t modify s json")
tk.MustQuery("select * from t").Check(testkit.Rows("{\"k1\": \"value\"} {\"k1\": \"value\"} {\"k1\": \"value\"} {\"k1\": \"value\"} {\"k1\": \"value\"} {\"k1\": \"value\"} \"{\\\"k1\\\": \\\"value\\\"}\" \"{\\\"k1\\\": \\\"value\\\"}\""))
tk.MustQuery("select * from t").Check(testkit.Rows("{\"k1\": \"value\"} {\"k1\": \"value\"} {\"k1\": \"value\"} {\"k1\": \"value\"} {\"k1\": \"value\"} {\"k1\": \"value\"} {\"k1\": \"value\"} {\"k1\": \"value\"}"))

reset(tk)
tk.MustExec("insert into t values ('123x', 'x123', 'abc', 'datetime', 'timestamp', 'date', '123', '123')")
Expand Down Expand Up @@ -651,7 +651,10 @@ func TestColumnTypeChangeFromStringToOthers(t *testing.T) {
reset(tk)
tk.MustExec("alter table t modify c char(15)")
tk.MustExec("insert into t(c) values ('{\"k1\": \"value\"')")
tk.MustExec("insert into t(e, s) values ('str', 'str')")
tk.MustGetErrCode("alter table t modify c json", errno.ErrInvalidJSONText)
tk.MustGetErrCode("alter table t modify e json", errno.ErrInvalidJSONText)
tk.MustGetErrCode("alter table t modify s json", errno.ErrInvalidJSONText)

// MySQL will get "ERROR 1366 (HY000): Incorrect DECIMAL value: '0' for column '' at row -1" error.
tk.MustExec("insert into t(vc) values ('abc')")
Expand Down
8 changes: 8 additions & 0 deletions types/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,14 @@ func (d *Datum) convertToMysqlJSON(_ *stmtctx.StatementContext, _ *FieldType) (r
if j, err = json.ParseBinaryFromString(d.GetString()); err == nil {
ret.SetMysqlJSON(j)
}
case KindMysqlSet, KindMysqlEnum:
var j json.BinaryJSON
var s string
if s, err = d.ToString(); err == nil {
if j, err = json.ParseBinaryFromString(s); err == nil {
ret.SetMysqlJSON(j)
}
}
case KindInt64:
i64 := d.GetInt64()
ret.SetMysqlJSON(json.CreateBinary(i64))
Expand Down

0 comments on commit 53b0c30

Please sign in to comment.