mirror of
https://github.com/pikami/cosmium.git
synced 2025-12-19 17:00:37 +00:00
Implement UPPER/LOWER; minor Fixes
This commit is contained in:
@@ -89,6 +89,8 @@ const (
|
||||
FunctionCallIndexOf FunctionCallType = "IndexOf"
|
||||
FunctionCallToString FunctionCallType = "ToString"
|
||||
FunctionCallIn FunctionCallType = "In"
|
||||
FunctionCallUpper FunctionCallType = "Upper"
|
||||
FunctionCallLower FunctionCallType = "Lower"
|
||||
)
|
||||
|
||||
type FunctionCall struct {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -312,6 +312,16 @@ StringFunctions <- StringEqualsExpression
|
||||
/ ToStringExpression
|
||||
/ ConcatExpression
|
||||
/ ThreeArgumentStringFunctionExpression
|
||||
/ UpperExpression
|
||||
/ LowerExpression
|
||||
|
||||
UpperExpression <- "UPPER"i ws "(" ex:SelectItem ")" {
|
||||
return parsers.FunctionCall{Type: parsers.FunctionCallUpper, Arguments: []interface{}{ex}}, nil
|
||||
}
|
||||
|
||||
LowerExpression <- "LOWER"i ws "(" ex:SelectItem ")" {
|
||||
return parsers.FunctionCall{Type: parsers.FunctionCallLower, Arguments: []interface{}{ex}}, nil
|
||||
}
|
||||
|
||||
StringEqualsExpression <- StringEquals ws "(" ws ex1:SelectItem ws "," ws ex2:SelectItem ws ignoreCase:("," ws boolean:SelectItem { return boolean, nil })? ")" {
|
||||
return parsers.FunctionCall{Type: parsers.FunctionCallStringEquals, Arguments: []interface{}{ex1, ex2, ignoreCase}}, nil
|
||||
|
||||
@@ -288,4 +288,52 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
t.Run("Should parse function UPPER()", func(t *testing.T) {
|
||||
testQueryParse(
|
||||
t,
|
||||
`SELECT UPPER(c.id) FROM c`,
|
||||
parsers.SelectStmt{
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{
|
||||
Type: parsers.SelectItemTypeFunctionCall,
|
||||
Value: parsers.FunctionCall{
|
||||
Type: parsers.FunctionCallUpper,
|
||||
Arguments: []interface{}{
|
||||
parsers.SelectItem{
|
||||
Path: []string{"c", "id"},
|
||||
Type: parsers.SelectItemTypeField,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
t.Run("Should parse function LOWER()", func(t *testing.T) {
|
||||
testQueryParse(
|
||||
t,
|
||||
`SELECT LOWER(c.id) FROM c`,
|
||||
parsers.SelectStmt{
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{
|
||||
Type: parsers.SelectItemTypeFunctionCall,
|
||||
Value: parsers.FunctionCall{
|
||||
Type: parsers.FunctionCallLower,
|
||||
Arguments: []interface{}{
|
||||
parsers.SelectItem{
|
||||
Path: []string{"c", "id"},
|
||||
Type: parsers.SelectItemTypeField,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user