The TSqlOperator
value given to ParseInput chooses the
comparison operator written into SQLExpression.
It does not change parsing or validation; it only changes the shape of
the SQL fragment.
| Operator | Single value | List | Range |
|---|---|---|---|
sopEqual |
= value |
IN (...) |
BETWEEN x AND y |
sopNotEqual |
<> value |
NOT IN (...) |
NOT BETWEEN x AND y |
sopGreaterEqual |
>= value |
IN (...) |
BETWEEN x AND y |
sopLessEqual |
<= value |
IN (...) |
BETWEEN x AND y |
sopGreater |
> value |
IN (...) |
BETWEEN x AND y |
sopLess |
< value |
IN (...) |
BETWEEN x AND y |
sopLikeRight |
LIKE 'value%' |
IN (...) |
BETWEEN x AND y |
sopLikeLeft |
LIKE '%value' |
IN (...) |
BETWEEN x AND y |
sopLikeBoth |
LIKE '%value%' |
IN (...) |
BETWEEN x AND y |
sopContainsAny |
ElevateDB: CONTAINS ANY 'value'; others:
LIKE '%value%' |
collapsed: ElevateDB CONTAINS ANY 'w1 ... wN'; others
LIKE '%w1%...%wN%' |
BETWEEN x AND y |
sopContainsAll |
ElevateDB: CONTAINS ALL 'value'; others:
LIKE '%value%' |
collapsed: ElevateDB CONTAINS ALL 'w1 ... wN'; others
LIKE '%w1%...%wN%' |
BETWEEN x AND y |
The default operator is sopEqual.
For lists (otList) only sopEqual and
sopNotEqual give different output; every other operator
gives IN (...), as sopEqual (except the
CONTAINS operators, below).
Input: 1;2;3, itInteger, sopGreaterEqual
SQLExpression: IN (1, 2, 3) -- not >= 1, 2, 3
Input: 1;2;3, itInteger, sopNotEqual
SQLExpression: NOT IN (1, 2, 3)
For ranges (otRange) only sopEqual and
sopNotEqual give different output; every other operator
gives BETWEEN ... AND ....
Input: 1~100, itInteger, sopLessEqual
SQLExpression: BETWEEN 1 AND 100 -- not <= 1~100
Input: 1~100, itInteger, sopNotEqual
SQLExpression: NOT BETWEEN 1 AND 100
When the single value is NULL (empty input for a typed
value, or itString with opEmptyStringNull),
sopNotEqual gives IS NOT NULL and every other
operator gives IS NULL.
Input: (empty), itInteger, sopGreater
SQLExpression: IS NULL -- not > NULL
Input: (empty), itDate, sopNotEqual
SQLExpression: IS NOT NULL
Empty input for itString without
opEmptyStringNull is the empty string '', not
NULL: the operators compare with it (= '',
<> '', >= ''…). The LIKE operators
give LIKE '%', which matches every value that is not
NULL, and so do the CONTAINS operators outside ElevateDB;
on sqlElevateDB they give CONTAINS ANY '' /
CONTAINS ALL ''. To leave the field out of the filter,
check ResultType
(otEmpty).
sopLikeRight, sopLikeLeft and
sopLikeBoth apply to itString single values
only. For other types and for lists and ranges they behave as
sopEqual.
The value is escaped before it goes into the pattern: except on
sqlAccess (below), \, % and
_ are prefixed with \. For every dialect
except sqlBDEParadox and sqlAccess the clause
ESCAPE '\' is added (ESCAPE '\\' on
sqlMySQL, where the backslashes of the pattern are doubled
too: 100% -> LIKE '%100\\%%' ESCAPE '\\').
On sqlBDEParadox the characters are still replaced but no
ESCAPE clause is written, because the BDE SQL layer does
not support it reliably.
sqlAccess has no ESCAPE clause: Jet/ACE SQL
does not support it. There, %, _ and
[ are written as the one-character classes
[%], [_] and [[], and
\ is not special: a_b ->
LIKE '%a[_]b%'.
Input: O'Brien, itString, sopLikeLeft, sqlElevateDB
SQLExpression: LIKE '%O''Brien' ESCAPE '\'
Input: 100%, itString, sopLikeBoth, sqlElevateDB
SQLExpression: LIKE '%100\%%' ESCAPE '\'
sopContainsAny and sopContainsAll apply to
itString values only; for other types they behave as
sopEqual.
On sqlElevateDB the native full-text predicates are
used. ElevateDB reads %, _ and \
as literals there, so they are not escaped; only single quotes are
doubled.
Input: hello world, itString, sopContainsAny, sqlElevateDB
SQLExpression: CONTAINS ANY 'hello world'
Input: hello world, itString, sopContainsAll, sqlElevateDB
SQLExpression: CONTAINS ALL 'hello world'
On the other dialects both fall back to LIKE '%value%'
with the escaping of sopLikeBoth. The whole value is one
pattern: hello world gives
LIKE '%hello world%'. To match separate words, type them as
a list (hello;world).
A list is collapsed into a single argument instead
of IN (...). Empty tokens (NULL and
'') are left out.
On sqlElevateDB the words are joined with a space:
Input: hello;world, itString, sopContainsAny, sqlElevateDB
SQLExpression: CONTAINS ANY 'hello world'
On the other dialects the words are escaped and joined with
%:
Input: hello;world, itString, sopContainsAny, sqlMySQL
SQLExpression: LIKE '%hello%world%' ESCAPE '\\'
In the LIKE fallback the order of the words matters:
%hello%world% matches hello followed by
world, not world followed by
hello. The ElevateDB predicates do not depend on the
order.
For ranges the CONTAINS operators give
BETWEEN ... AND ..., as sopEqual: full-text
search and ranges do not mix.