Skip to content

Commit 52a5f8d

Browse files
committed
[fix] notContains rule did not work because of INSTR expected value -1
1 parent 6790c9b commit 52a5f8d

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Blocks can be nested like next
5656
}
5757
```
5858

59-
### between / notBeetween
59+
### between / notBetween
6060

6161
For those operations, both start and end values can be provided
6262

sql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func GetSQL(data Filter, config *SQLConfig) (string, []interface{}, error) {
6060
case "contains":
6161
return fmt.Sprintf("INSTR(%s, ?) > 0", data.Field), values, nil
6262
case "notContains":
63-
return fmt.Sprintf("INSTR(%s, ?) < 0", data.Field), values, nil
63+
return fmt.Sprintf("INSTR(%s, ?) = 0", data.Field), values, nil
6464
case "lessOrEqual":
6565
return fmt.Sprintf("%s <= ?", data.Field), values, nil
6666
case "greaterOrEqual":

sql_test.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ var cases = [][]string{
5050
},
5151
[]string{
5252
`{ "glue":"and", "rules":[{ "field": "a", "condition":{ "type":"notContains", "filter":1 }}]}`,
53-
"INSTR(a, ?) < 0",
53+
"INSTR(a, ?) = 0",
5454
"1",
5555
},
5656
[]string{
@@ -130,7 +130,6 @@ var cases = [][]string{
130130
},
131131
}
132132

133-
134133
func anyToStringArray(some []interface{}) (string, error) {
135134
out := make([]string, 0, len(some))
136135
for _, x := range some {
@@ -229,10 +228,10 @@ func TestCustomOperation(t *testing.T) {
229228

230229
sql, vals, err := GetSQL(format, &SQLConfig{
231230
Operations: map[string]CustomOperation{
232-
"is null" : func(n string, r string, values []interface{}) (string, []interface{}, error) {
231+
"is null": func(n string, r string, values []interface{}) (string, []interface{}, error) {
233232
return fmt.Sprintf("%s IS NULL", n), NoValues, nil
234233
},
235-
"range100" : func(n string, r string, values []interface{}) (string, []interface{}, error) {
234+
"range100": func(n string, r string, values []interface{}) (string, []interface{}, error) {
236235
out := []interface{}{values[0], values[0]}
237236
return fmt.Sprintf("( %s > ? AND %s < ? + 100 )", n, n), out, nil
238237
},
@@ -250,15 +249,15 @@ func TestCustomOperation(t *testing.T) {
250249
return
251250
}
252251

253-
valsStr, err := anyToStringArray(vals)
254-
if err != nil {
255-
t.Errorf("can't convert parameters\nj: %s\n%f", cOrC, err)
256-
return
257-
}
252+
valsStr, err := anyToStringArray(vals)
253+
if err != nil {
254+
t.Errorf("can't convert parameters\nj: %s\n%f", cOrC, err)
255+
return
256+
}
258257

259-
check = "500,500"
260-
if valsStr != check {
261-
t.Errorf("wrong sql generated\nj: %s\ns: %s\nr: %s", cOrC, check, valsStr)
262-
return
263-
}
264-
}
258+
check = "500,500"
259+
if valsStr != check {
260+
t.Errorf("wrong sql generated\nj: %s\ns: %s\nr: %s", cOrC, check, valsStr)
261+
return
262+
}
263+
}

0 commit comments

Comments
 (0)