Unverified Commit 7545e579 authored by ti-srebot's avatar ti-srebot Committed by GitHub
Browse files

cherry pick #22100 to release-4.0 (#22103)

Showing with 27 additions and 1 deletion
+27 -1
......@@ -193,7 +193,13 @@ func (s *SelectIntoExec) dumpToOutfile() error {
case mysql.TypeJSON:
s.fieldBuf = append(s.fieldBuf, row.GetJSON(j).String()...)
}
s.lineBuf = append(s.lineBuf, s.escapeField(s.fieldBuf)...)
switch col.GetType().EvalType() {
case types.ETString, types.ETJson:
s.lineBuf = append(s.lineBuf, s.escapeField(s.fieldBuf)...)
default:
s.lineBuf = append(s.lineBuf, s.fieldBuf...)
}
if (encloseFlag && !encloseOpt) ||
(encloseFlag && encloseOpt && s.considerEncloseOpt(et)) {
s.lineBuf = append(s.lineBuf, encloseByte)
......
......@@ -246,3 +246,23 @@ func (s *testSuite1) TestDumpReal(c *C) {
c.Assert(string(buf), Equals, testCase.result)
}
}
func (s *testSuite1) TestEscapeType(c *C) {
outfile := randomSelectFilePath("TestEscapeType")
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec(`create table t (
a int,
b double,
c varchar(10),
d blob,
e json,
f set('1', '2', '3'),
g enum('1', '2', '3'))`)
tk.MustExec(`insert into t values (1, 1, "1", "1", '{"key": 1}', "1", "1")`)
tk.MustExec(fmt.Sprintf("select * from t into outfile '%v' fields terminated by ',' escaped by '1'", outfile))
cmpAndRm(`1,1,11,11,{"key": 11},11,11
`, outfile, c)
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment