Skip to content

Commit 42e81ef

Browse files
authored
Merge pull request #627 from domyway/master
support insert argument type json.RawMessage
2 parents e0abcca + 2a94a2b commit 42e81ef

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

client/client_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package client
22

33
import (
4+
"encoding/json"
45
"flag"
56
"fmt"
67
"strings"
@@ -82,6 +83,7 @@ func (s *clientTestSuite) testConn_CreateTable(c *C) {
8283
e enum("test1", "test2"),
8384
u tinyint unsigned,
8485
i tinyint,
86+
j json,
8587
PRIMARY KEY (id)
8688
) ENGINE=InnoDB DEFAULT CHARSET=utf8`
8789

@@ -184,6 +186,14 @@ func (s *clientTestSuite) TestConn_Insert(c *C) {
184186
c.Assert(pkg.AffectedRows, Equals, uint64(1))
185187
}
186188

189+
func (s *clientTestSuite) TestConn_Insert2(c *C) {
190+
str := `insert into mixer_test_conn (id, j) values(?, ?)`
191+
j := json.RawMessage(`[]`)
192+
pkg, err := s.c.Execute(str, []interface{}{2, j}...)
193+
c.Assert(err, IsNil)
194+
c.Assert(pkg.AffectedRows, Equals, uint64(1))
195+
}
196+
187197
func (s *clientTestSuite) TestConn_Select(c *C) {
188198
str := `select str, f, e from mixer_test_conn where id = 1`
189199

client/stmt.go

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package client
22

33
import (
44
"encoding/binary"
5+
"encoding/json"
56
"fmt"
67
"math"
78

@@ -127,6 +128,9 @@ func (s *Stmt) write(args ...interface{}) error {
127128
case []byte:
128129
paramTypes[i<<1] = MYSQL_TYPE_STRING
129130
paramValues[i] = append(PutLengthEncodedInt(uint64(len(v))), v...)
131+
case json.RawMessage:
132+
paramTypes[i<<1] = MYSQL_TYPE_STRING
133+
paramValues[i] = append(PutLengthEncodedInt(uint64(len(v))), v...)
130134
default:
131135
return fmt.Errorf("invalid argument type %T", args[i])
132136
}

0 commit comments

Comments
 (0)