Empty strings now match an EMPTY sql clause
This commit is contained in:
parent
bece5d1f07
commit
069baf71b7
2 changed files with 18 additions and 4 deletions
14
db/fetch.go
14
db/fetch.go
|
@ -592,6 +592,8 @@ func binaryCheck(op sql.Token, l, r, lo, ro interface{}, d *data.Doc) interface{
|
|||
return op == sql.EQ
|
||||
case *sql.Empty:
|
||||
return op == sql.EQ
|
||||
case string:
|
||||
return chkLen(op, r)
|
||||
case []interface{}:
|
||||
return chkArrayR(op, l, r)
|
||||
case map[string]interface{}:
|
||||
|
@ -640,6 +642,8 @@ func binaryCheck(op sql.Token, l, r, lo, ro interface{}, d *data.Doc) interface{
|
|||
}
|
||||
case time.Time:
|
||||
return chkString(op, l, r.String())
|
||||
case *sql.Empty:
|
||||
return chkLen(op, l)
|
||||
case *sql.Thing:
|
||||
return chkString(op, l, r.String())
|
||||
case *regexp.Regexp:
|
||||
|
@ -769,6 +773,16 @@ func chkOp(op sql.Token) int8 {
|
|||
}
|
||||
}
|
||||
|
||||
func chkLen(op sql.Token, s string) (val bool) {
|
||||
switch op {
|
||||
case sql.EQ:
|
||||
return len(s) == 0
|
||||
case sql.NEQ:
|
||||
return len(s) != 0
|
||||
}
|
||||
return negOp(op)
|
||||
}
|
||||
|
||||
func chkBool(op sql.Token, a, b bool) (val bool) {
|
||||
switch op {
|
||||
case sql.EQ:
|
||||
|
|
|
@ -467,7 +467,7 @@ func TestFetch(t *testing.T) {
|
|||
So(err, ShouldBeNil)
|
||||
So(res, ShouldHaveLength, 46)
|
||||
|
||||
So(res[2].Result, ShouldHaveLength, 0)
|
||||
So(res[2].Result, ShouldHaveLength, 1)
|
||||
So(res[3].Result, ShouldHaveLength, 1)
|
||||
So(res[4].Result, ShouldHaveLength, 1)
|
||||
So(res[5].Result, ShouldHaveLength, 1)
|
||||
|
@ -476,7 +476,7 @@ func TestFetch(t *testing.T) {
|
|||
So(res[8].Result, ShouldHaveLength, 1)
|
||||
So(res[9].Result, ShouldHaveLength, 1)
|
||||
|
||||
So(res[10].Result, ShouldHaveLength, 0)
|
||||
So(res[10].Result, ShouldHaveLength, 1)
|
||||
So(res[11].Result, ShouldHaveLength, 1)
|
||||
So(res[12].Result, ShouldHaveLength, 1)
|
||||
So(res[13].Result, ShouldHaveLength, 1)
|
||||
|
@ -485,7 +485,7 @@ func TestFetch(t *testing.T) {
|
|||
So(res[16].Result, ShouldHaveLength, 1)
|
||||
So(res[17].Result, ShouldHaveLength, 1)
|
||||
|
||||
So(res[18].Result, ShouldHaveLength, 1)
|
||||
So(res[18].Result, ShouldHaveLength, 0)
|
||||
So(res[19].Result, ShouldHaveLength, 0)
|
||||
So(res[20].Result, ShouldHaveLength, 0)
|
||||
So(res[21].Result, ShouldHaveLength, 0)
|
||||
|
@ -494,7 +494,7 @@ func TestFetch(t *testing.T) {
|
|||
So(res[24].Result, ShouldHaveLength, 0)
|
||||
So(res[25].Result, ShouldHaveLength, 0)
|
||||
|
||||
So(res[26].Result, ShouldHaveLength, 1)
|
||||
So(res[26].Result, ShouldHaveLength, 0)
|
||||
So(res[27].Result, ShouldHaveLength, 0)
|
||||
So(res[28].Result, ShouldHaveLength, 0)
|
||||
So(res[29].Result, ShouldHaveLength, 0)
|
||||
|
|
Loading…
Reference in a new issue