Skip to content

Commit

Permalink
cherry pick pingcap#22175 to release-5.0-rc
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
xiongjiwei authored and ti-srebot committed Jan 5, 2021
1 parent 215d8a2 commit 8aba035
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion executor/select_into.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (s *SelectIntoExec) dumpToOutfile() error {
}
s.fieldBuf = s.fieldBuf[:0]
switch col.GetType().Tp {
case mysql.TypeTiny, mysql.TypeShort, mysql.TypeInt24, mysql.TypeLong:
case mysql.TypeTiny, mysql.TypeShort, mysql.TypeInt24, mysql.TypeLong, mysql.TypeYear:
s.fieldBuf = strconv.AppendInt(s.fieldBuf, row.GetInt64(j), 10)
case mysql.TypeLonglong:
if mysql.HasUnsignedFlag(col.GetType().Flag) {
Expand Down
36 changes: 36 additions & 0 deletions executor/select_into_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,39 @@ func (s *testSuite1) TestDumpReal(c *C) {
c.Assert(string(buf), Equals, testCase.result)
}
}
<<<<<<< HEAD
=======

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)
}

func (s *testSuite1) TestYearType(c *C) {
outfile := randomSelectFilePath("TestYearType")
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(time1 year(4) default '2030');")
tk.MustExec("insert into t values (2010), (2011), (2012);")
tk.MustExec("insert into t values ();")

tk.MustExec(fmt.Sprintf("select * from t into outfile '%v' fields terminated by ',' optionally enclosed by '\"' lines terminated by '\\n';", outfile))
cmpAndRm("2010\n2011\n2012\n2030\n", outfile, c)
}
>>>>>>> 85d8d0605... executor: fix select into outfile with year type column has no data (#22175)

0 comments on commit 8aba035

Please sign in to comment.