diff --git a/db/fetch.go b/db/fetch.go index edec04ee..e7016a90 100644 --- a/db/fetch.go +++ b/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: diff --git a/db/fetch_test.go b/db/fetch_test.go index 921505b8..2b7400e1 100644 --- a/db/fetch_test.go +++ b/db/fetch_test.go @@ -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)