BSL201 — Incorrect use of 'LIKE'¶
Summary¶
Incorrect use of 'LIKE'
Identifiers¶
| Field | Value |
|---|---|
| Rule code | BSL201 |
| Compatible alias | IncorrectUseLikeInQuery |
| Severity | WARNING |
| Enabled by default | Yes |
| Implemented | Yes |
| Tags | query, correctness |
Behavior¶
- The public identifier
BSL201and aliasIncorrectUseLikeInQueryare stable. - The rule reports the cases documented on this page.
- Suppressions and project configuration are applied before publication.
- The rule requires neither an external analyzer nor network access.
Configuration and suppression¶
BSL### is the primary stable identifier. The compatible alias is accepted
in select, ignore, and compatible block suppression comments.
All three suppression families support both a current line and a range. When an opening comment follows code, it affects only that line. Use any one form:
noqa:
bsl-disable:
- compatible
BSLLSform:
When the same opening comment is on a line by itself, it starts a range. Close it with the matching marker from the same family:
// noqa: BSL201
// code without this diagnostic
// noqa-enable: BSL201
// bsl-disable: BSL201
// code without this diagnostic
// bsl-enable: BSL201
// BSLLS:IncorrectUseLikeInQuery-off
// code without this diagnostic
// BSLLS:IncorrectUseLikeInQuery-on
To disable the rule until the end of the file, omit the closing
noqa-enable, bsl-enable, or BSLLS:…-on marker.
Opening and closing markers must belong to the same family.
Description¶
When using the operator LIKE in the query text, it is allowed to use only
- constant string literals
- query parameters
It is forbidden to form a template string using calculations, use string concatenation using the query language.
Queries in which the control characters of the operator template LIKE are in query fields or in calculated expressions are interpreted differently on different DBMSs.
Examples¶
String concatenation by language features¶
Allowed:
Not allowed:
Operator template control characters LIKE are found in query fields or in calculated expressions¶
For example, instead of:
Query = New Query("
|SELECT
| Goods.Ref
|FROM
| Catalog.Goods AS Goods
|WHERE
| Goods.Country.Description LOKE &NameTemplate + "_"
|");
Query.SetParameter("NameTemplate", "FU");
Nessesary to use:
Query = New Query("
|SELECT
| Goods.Ref
|FROM
| Catalog.Goods AS Goods
|WHERE
| Goods.Country.Description LOKE &NameTemplate
|");
Query.SetParameter("NameTemplate", "FU_");