expressions: Process []byte in like.go

Support "LIKE BINARY expr"
This commit is contained in:
shenli
2015-09-17 13:56:31 +08:00
parent f6e34c31b5
commit f7662b71db
2 changed files with 22 additions and 1 deletions

View File

@ -103,7 +103,12 @@ func (p *PatternLike) Eval(ctx context.Context, args map[interface{}]interface{}
}
spattern, ok := pattern.(string)
if !ok {
return nil, errors.Errorf("non-string pattern in LIKE: %v (Value of type %T)", pattern, pattern)
bpattern, ok := pattern.([]byte)
if !ok {
return nil, errors.Errorf("non-string pattern in LIKE: %v (Value of type %T)", pattern, pattern)
}
// TODO: BINARY pattern match should be case-insensitive
spattern = string(bpattern)
}
p.patChars, p.patTypes = compilePattern(spattern)

View File

@ -105,4 +105,20 @@ func (*testLikeSuite) TestEval(c *C) {
pattern.Expr = mockExpr{isStatic: false, val: nil}
_, err = pattern.Eval(nil, nil)
c.Assert(err, IsNil)
// Testcase for "LIKE BINARY xxx"
pattern = &PatternLike{
Expr: mockExpr{isStatic: true, val: "slien"},
Pattern: mockExpr{isStatic: true, val: []byte("%E%")},
}
v, err := pattern.Eval(nil, nil)
c.Assert(err, IsNil)
c.Assert(v, IsTrue)
pattern = &PatternLike{
Expr: mockExpr{isStatic: true, val: "slin"},
Pattern: mockExpr{isStatic: true, val: []byte("%E%")},
}
v, err = pattern.Eval(nil, nil)
c.Assert(err, IsNil)
c.Assert(v, IsFalse)
}