diff --git a/client/client_test.go b/client/client_test.go index 121051f1b..8a1b893d4 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -1,6 +1,7 @@ package client import ( + "encoding/json" "flag" "fmt" "strings" @@ -82,6 +83,7 @@ func (s *clientTestSuite) testConn_CreateTable(c *C) { e enum("test1", "test2"), u tinyint unsigned, i tinyint, + j json, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8` @@ -184,6 +186,14 @@ func (s *clientTestSuite) TestConn_Insert(c *C) { c.Assert(pkg.AffectedRows, Equals, uint64(1)) } +func (s *clientTestSuite) TestConn_Insert2(c *C) { + str := `insert into mixer_test_conn (id, j) values(?, ?)` + j := json.RawMessage(`[]`) + pkg, err := s.c.Execute(str, []interface{}{2, j}...) + c.Assert(err, IsNil) + c.Assert(pkg.AffectedRows, Equals, uint64(1)) +} + func (s *clientTestSuite) TestConn_Select(c *C) { str := `select str, f, e from mixer_test_conn where id = 1` diff --git a/client/stmt.go b/client/stmt.go index 07e13357e..e0d5f1d30 100644 --- a/client/stmt.go +++ b/client/stmt.go @@ -2,6 +2,7 @@ package client import ( "encoding/binary" + "encoding/json" "fmt" "math" @@ -127,6 +128,9 @@ func (s *Stmt) write(args ...interface{}) error { case []byte: paramTypes[i<<1] = MYSQL_TYPE_STRING paramValues[i] = append(PutLengthEncodedInt(uint64(len(v))), v...) + case json.RawMessage: + paramTypes[i<<1] = MYSQL_TYPE_STRING + paramValues[i] = append(PutLengthEncodedInt(uint64(len(v))), v...) default: return fmt.Errorf("invalid argument type %T", args[i]) }