Skip to content
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

executor: fix select into outfile with year type column has no data #22175

Merged
merged 4 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
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
13 changes: 13 additions & 0 deletions executor/select_into_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,16 @@ func (s *testSuite1) TestEscapeType(c *C) {
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)
}