This function allows you to create in FlexQuery expressions a construct similar to switch statement in Java. On a large number of cases, it may work substantially faster than running through the equivalent number of consecutive conditional statements. For example:
switch (
val, // the value to match to switch cases
SwitchCase[] ( // create an array of cases
SwitchCase ( // create 1-st case
'A', // the matching value, which
// triggers that case
1 // the result to be returned in that
// case by switch() function
),
SwitchCase ( // create 2-nd case
'B', // the matching value
// instead of a single value, specify
// for that case a subquery to evaluate
FlexQuery ({
... // do something here
2 // the result to be returned by switch()
})
),
SwitchCase ( // create 3-rd case
// it matches several values at once
// specified in an array
Array ('C', 'D', 'E'),
// a subquery to evaluate in that case
FlexQuery ({
... // do something here
val // the result to be returned:
// the same value as passed
// to the switch()
})
)
),
// the default subquery: executed
// when none of the cases matched
FlexQuery ({
... // do something here
-1 // the result to be returned by switch()
})
);
value
cases
SwitchCase
objects representing each switch case.
Such an array can be created only with a function-call-like construct looking as follows
SwitchCase[] (
...
)
SwitchCase()
function and
listed inside the round brackets separated with commas.
defaultQuery
The subquery must be created using FlexQuery()
function. The result returned by the subquery will be
the function's result.
When this parameter is omitted or null
and no matching case has been found,
the function does nothing and returns null
.
null
if none specified.
SwitchCase(), FlexQuery()