diff --git a/mysql/time_test.go b/mysql/time_test.go index f58851ace2a9a..1f11d3a614443 100644 --- a/mysql/time_test.go +++ b/mysql/time_test.go @@ -671,3 +671,26 @@ func (s *testTimeSuite) TestDurationClock(c *C) { c.Assert(d.MicroSecond(), Equals, t.MicroSecond) } } + +func (s *testTimeSuite) TestParseDateFormat(c *C) { + tbl := []struct { + Input string + Result []string + }{ + {"2011-11-11 10:10:10.123456", []string{"2011", "11", "11", "10", "10", "10", "123456"}}, + {" 2011-11-11 10:10:10.123456 ", []string{"2011", "11", "11", "10", "10", "10", "123456"}}, + {"2011-11-11 10", []string{"2011", "11", "11", "10"}}, + {"2011-11-11T10:10:10.123456", []string{"2011", "11", "11", "10", "10", "10", "123456"}}, + {"2011:11:11T10:10:10.123456", []string{"2011", "11", "11", "10", "10", "10", "123456"}}, + {"xx2011-11-11 10:10:10", nil}, + {"T10:10:10", nil}, + {"2011-11-11x", nil}, + {"2011-11-11 10:10:10", nil}, + {"xxx 10:10:10", nil}, + } + + for _, t := range tbl { + r := parseDateFormat(t.Input) + c.Assert(r, DeepEquals, t.Result) + } +} diff --git a/tidb_test.go b/tidb_test.go index ebfad85886f2b..133cced2700a8 100644 --- a/tidb_test.go +++ b/tidb_test.go @@ -1245,6 +1245,14 @@ func (s *testSessionSuite) TestResultType(c *C) { c.Assert(fs[0].Col.FieldType.Tp, Equals, mysql.TypeString) } +func (s *testSessionSuite) TestBuiltin(c *C) { + store := newStore(c, s.dbName) + se := newSession(c, store, s.dbName) + + // Testcase for https://github.com/pingcap/tidb/issues/382 + mustExecFailed(c, se, `select cast("xxx 10:10:10" as datetime)`) +} + func newSession(c *C, store kv.Storage, dbName string) Session { se, err := CreateSession(store) c.Assert(err, IsNil)