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

server: fix insert zero timestamp bug with prepared statement #7506

Merged
merged 5 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion server/conn_stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion server/conn_stmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -120,7 +121,7 @@ func (ts ConnTestSuite) TestParseStmtArgs(c *C) {
[]byte{0x00},
},
nil,
"0",
types.ZeroDatetimeStr,
},
// Tests for time
{
Expand Down
13 changes: 13 additions & 0 deletions session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down