diff --git a/server/conn_stmt.go b/server/conn_stmt.go index 9ab74ec2cb72e..d874d8ea3d182 100644 --- a/server/conn_stmt.go +++ b/server/conn_stmt.go @@ -42,6 +42,7 @@ import ( "github.com/juju/errors" "github.com/pingcap/tidb/mysql" + "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/hack" "golang.org/x/net/context" ) @@ -354,7 +355,7 @@ func parseStmtArgs(args []interface{}, boundParams [][]byte, nullBitmap, paramTy pos++ switch length { case 0: - args[i] = "0" + args[i] = types.ZeroDatetimeStr case 4: pos, args[i] = parseBinaryDate(pos, paramValues) case 7: diff --git a/server/conn_stmt_test.go b/server/conn_stmt_test.go index fdfce13a338fe..d131e39d6f22c 100644 --- a/server/conn_stmt_test.go +++ b/server/conn_stmt_test.go @@ -17,6 +17,7 @@ import ( . "github.com/pingcap/check" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/terror" + "github.com/pingcap/tidb/types" ) func (ts ConnTestSuite) TestParseStmtArgs(c *C) { @@ -120,7 +121,7 @@ func (ts ConnTestSuite) TestParseStmtArgs(c *C) { []byte{0x00}, }, nil, - "0", + types.ZeroDatetimeStr, }, // Tests for time { diff --git a/session/session_test.go b/session/session_test.go index 88f921afc7391..d95d7e1a58032 100644 --- a/session/session_test.go +++ b/session/session_test.go @@ -630,6 +630,19 @@ func (s *testSessionSuite) TestLastInsertID(c *C) { c.Assert(lastInsertID+2, Equals, currLastInsertID) } +func (s *testSessionSuite) TestPrepareZero(c *C) { + tk := testkit.NewTestKitWithInit(c, s.store) + tk.MustExec("drop table if exists t") + tk.MustExec("create table t(v timestamp)") + tk.MustExec("prepare s1 from 'insert into t (v) values (?)'") + tk.MustExec("set @v1='0'") + _, rs := tk.Exec("execute s1 using @v1") + c.Assert(rs, NotNil) + tk.MustExec("set @v2='" + types.ZeroDatetimeStr + "'") + tk.MustExec("execute s1 using @v2") + tk.MustQuery("select v from t").Check(testkit.Rows("0000-00-00 00:00:00")) +} + func (s *testSessionSuite) TestPrimaryKeyAutoIncrement(c *C) { tk := testkit.NewTestKitWithInit(c, s.store) tk.MustExec("drop table if exists t")