classPatternMatch
final class PatternMatch
implements Scalar
uses Snapshot
@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.
$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, '!']$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\InvalidConstructionProperties§
public PatternOperator $operatorpublic Scalar $leftpublic Scalar $rightpublic bool $negated = falsepublic Scalar|null $escape = nullMethods§
public function __construct(
public PatternOperator $operator,
public Scalar $left,
public Scalar $right,
public bool $negated = false,
public Scalar|null $escape = null,
)Parameters
$operator | PatternOperator | The operator |
$left | Scalar | The matched expression |
$right | Scalar | The pattern |
$negated | bool | Whether NOT is written before the operator |
$escape | Scalar|null | The escape character expression |
Calls 6
- new Precedence line 65
- static-call Check::input() line 66
- method-call Precedence::closing() line 66
- class-const Precedence::EQUALITY() line 66
- method-call Precedence::opening() line 67
- method-call Precedence::takesEscape() line 68
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives the operands and the result of the function the operator calls.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 14
- method-call Derivation::scalar() line 76
- new RowValueUse line 80
- method-call RowValueUse::single() line 81
- class-const PatternOperator::Regexp() line 89
- class-const PatternOperator::Match() line 89
- new ScalarFact line 90
- new Dependent line 90
- new UndeclaredRoutine line 90
- new QualifiedName line 90
- new Name line 90
- class-const Nullability::Dependent() line 90
- method-call Storages::strict() line 93
- new Storages line 93
- class-const Storage::Integer() line 93
public function render(Output $out): voidWrites the match.
Parameters
$out | Output |
Calls 2
- method-call Output::node() line 101
- method-call Output::keyword() line 103
Test cases 12§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 8
PatternMatchTest::testDeriveScalarRecordsTheFactsOfEveryOperandcallsPatternMatchTest::testRefusesAMatchedOperandThatEndsInAWeakerOperatorcallsPatternMatchTest::testRefusesAnEscapeAfterAPatternThatWouldTakeItcallsPatternMatchTest::testRefusesAnEscapeOperandThatStartsWithAnEqualityOperatorcallsPatternMatchTest::testRefusesAPatternThatStartsWithAnEqualityOperatorcallsPatternMatchTest::testRenderGroupsToTheLeftcallsPatternMatchTest::testRenderWritesANewlyBuiltMatchcallsPatternMatchTest::testRenderWritesTheNegationAndTheEscapecalls