diff --git a/README.md b/README.md index f6c8522..1c87279 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ Blocks can be nested like next } ``` -### between / notBeetween +### between / notBetween For those operations, both start and end values can be provided diff --git a/sql.go b/sql.go index 4ca46cf..3c39434 100644 --- a/sql.go +++ b/sql.go @@ -60,7 +60,7 @@ func GetSQL(data Filter, config *SQLConfig) (string, []interface{}, error) { case "contains": return fmt.Sprintf("INSTR(%s, ?) > 0", data.Field), values, nil case "notContains": - return fmt.Sprintf("INSTR(%s, ?) < 0", data.Field), values, nil + return fmt.Sprintf("INSTR(%s, ?) = 0", data.Field), values, nil case "lessOrEqual": return fmt.Sprintf("%s <= ?", data.Field), values, nil case "greaterOrEqual": diff --git a/sql_test.go b/sql_test.go index a3cc99f..3100b06 100644 --- a/sql_test.go +++ b/sql_test.go @@ -50,7 +50,7 @@ var cases = [][]string{ }, []string{ `{ "glue":"and", "rules":[{ "field": "a", "condition":{ "type":"notContains", "filter":1 }}]}`, - "INSTR(a, ?) < 0", + "INSTR(a, ?) = 0", "1", }, []string{ @@ -130,7 +130,6 @@ var cases = [][]string{ }, } - func anyToStringArray(some []interface{}) (string, error) { out := make([]string, 0, len(some)) for _, x := range some { @@ -229,10 +228,10 @@ func TestCustomOperation(t *testing.T) { sql, vals, err := GetSQL(format, &SQLConfig{ Operations: map[string]CustomOperation{ - "is null" : func(n string, r string, values []interface{}) (string, []interface{}, error) { + "is null": func(n string, r string, values []interface{}) (string, []interface{}, error) { return fmt.Sprintf("%s IS NULL", n), NoValues, nil }, - "range100" : func(n string, r string, values []interface{}) (string, []interface{}, error) { + "range100": func(n string, r string, values []interface{}) (string, []interface{}, error) { out := []interface{}{values[0], values[0]} return fmt.Sprintf("( %s > ? AND %s < ? + 100 )", n, n), out, nil }, @@ -250,15 +249,15 @@ func TestCustomOperation(t *testing.T) { return } - valsStr, err := anyToStringArray(vals) - if err != nil { - t.Errorf("can't convert parameters\nj: %s\n%f", cOrC, err) - return - } + valsStr, err := anyToStringArray(vals) + if err != nil { + t.Errorf("can't convert parameters\nj: %s\n%f", cOrC, err) + return + } - check = "500,500" - if valsStr != check { - t.Errorf("wrong sql generated\nj: %s\ns: %s\nr: %s", cOrC, check, valsStr) - return - } -} \ No newline at end of file + check = "500,500" + if valsStr != check { + t.Errorf("wrong sql generated\nj: %s\ns: %s\nr: %s", cOrC, check, valsStr) + return + } +}