final class PatternMatch
    implements Scalar
    uses Snapshot
Public API: explicitly declared with @visibility public.

A pattern match: LIKE, GLOB, REGEXP or MATCH, optionally negated, optionally with an escape character.

Rule: SQLITE-PATTERN-MATCH-001. LIKE and GLOB call the built-in functions of those names: the result is INTEGER and NULL when an operand is NULL. REGEXP and MATCH call the application-defined functions regexp() and match(), which SQLite does not provide, so their result depends on the undeclared routine. Every operand is a single value (SQLITE-ROW-VALUE-USE-001). The operands must keep their place without parentheses (SQLITE-PRECEDENCE-001); the pattern before ESCAPE may not end in a pattern match without ESCAPE, which would take the ESCAPE. Source: https://sqlite.org/lang_expr.html#the_like_glob_regexp_match_and_extract_operators. Status: Implemented.

Reading a negated LIKE with an escape characterdoctest
$query = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze("SELECT a NOT LIKE 'x!%' ESCAPE '!' FROM t");
    $match = $query->statement->columns[0]->expression;
    [$match->operator, $match->negated, $match->escape->value] // => [\SqlSemantics\Platform\Sqlite\Statement\Expression\Operator\PatternOperator::Like, true, '!']
Refusing a pattern that the rendered SQL would associate differentlydoctest
$or = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('SELECT a OR b FROM t')->statement->columns[0]->expression;
    new \SqlSemantics\Platform\Sqlite\Statement\Expression\Operator\PatternMatch(\SqlSemantics\Platform\Sqlite\Statement\Expression\Operator\PatternOperator::Like, new \SqlSemantics\Platform\Sqlite\Statement\Expression\Literal\NullLiteral(), $or) // throws \SqlSemantics\Platform\Sqlite\Model\Diagnostic\InvalidConstruction

Properties§

public PatternOperator $operator
public Scalar $left
public Scalar $right
public bool $negated = false
public Scalar|null $escape = null

Methods§

public function __construct(
    public PatternOperator $operator,
    public Scalar $left,
    public Scalar $right,
    public bool $negated = false,
    public Scalar|null $escape = null,
)

Parameters

$operatorPatternOperatorThe operator
$leftScalarThe matched expression
$rightScalarThe pattern
$negatedboolWhether NOT is written before the operator
$escapeScalar|nullThe escape character expression
Calls 6
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFact

Derives the operands and the result of the function the operator calls.

Parameters

$derivationDerivation
$environmentEnvironment

Returns

Calls 14
public function render(Output $out): void

Writes the match.

Parameters

$outOutput
Calls 2

Test cases 12§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 8
Other tests reaching this symbol 4

Relations§

Instantiated in 1
Type checks 2
Type declarations 1