tidb: Convert bool type prepared statement args to int8

We handle bool as int8 in tidb.
This commit is contained in:
shenli
2015-09-07 18:36:46 +08:00
parent 222ea14314
commit cd01fa1dc4
2 changed files with 19 additions and 1 deletions

View File

@ -28,6 +28,7 @@ import (
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessionctx/db"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/util/types"
)
// Session context
@ -150,7 +151,14 @@ func (s *session) PrepareStmt(sql string) (stmtID uint32, paramCount int, fields
func checkArgs(args ...interface{}) error {
for i, v := range args {
switch v.(type) {
case nil, bool, float32, float64, string,
case bool:
// We do not handle bool as int8 in tidb.
vv, err := types.ToBool(v)
if err != nil {
return errors.Trace(err)
}
args[i] = vv
case nil, float32, float64, string,
int8, int16, int32, int64, int,
uint8, uint16, uint32, uint64, uint,
[]byte, time.Duration, time.Time:

View File

@ -392,6 +392,16 @@ func (s *testSessionSuite) TestPrimaryKeyAutoincrement(c *C) {
row, err = rs.FirstRow()
c.Assert(err, IsNil)
match(c, row, id, "abc", 1)
// Check for pass bool param to tidb prepared statement
mustExecSQL(c, se, "drop table if exists t")
mustExecSQL(c, se, "create table t (id tiny)")
mustExecSQL(c, se, "insert t values (?)", true)
rs = mustExecSQL(c, se, "select * from t")
c.Assert(rs, NotNil)
row, err = rs.FirstRow()
c.Assert(err, IsNil)
match(c, row, int8(1))
mustExecSQL(c, se, s.dropDBSQL)
}