cosmium/query_executors/memory_executor/string_functions.go

42 lines
965 B
Go
Raw Normal View History

2024-02-18 20:37:09 +00:00
package memoryexecutor
import (
"fmt"
"strings"
"github.com/pikami/cosmium/parsers"
)
func strings_StringEquals(arguments []interface{}, queryParameters map[string]interface{}, row RowType) bool {
ignoreCase := false
if len(arguments) > 2 && arguments[2] != nil {
ignoreCaseItem := arguments[2].(parsers.SelectItem)
if value, ok := getFieldValue(ignoreCaseItem, queryParameters, row).(bool); ok {
ignoreCase = value
}
}
ex1Item := arguments[0].(parsers.SelectItem)
ex2Item := arguments[1].(parsers.SelectItem)
ex1 := getFieldValue(ex1Item, queryParameters, row)
ex2 := getFieldValue(ex2Item, queryParameters, row)
var ok bool
var str1 string
var str2 string
if str1, ok = ex1.(string); !ok {
fmt.Println("StringEquals got parameters of wrong type")
}
if str2, ok = ex2.(string); !ok {
fmt.Println("StringEquals got parameters of wrong type")
}
if ignoreCase {
return strings.EqualFold(str1, str2)
}
return str1 == str2
}