classVariableAssignment
final class VariableAssignment
implements Scalar
uses Snapshot
@visibility public.An assignment to a user-defined variable inside an expression: @name := value.
The value is a complete expression: everything to the right of := belongs to it. An operator that takes an assignment as its left operand must therefore hold it in a grouping.
Rule: MYSQL-VARIABLE-ASSIGNMENT-001. Facts: the assignment yields the assigned value, so its type and NULL fact are those of the value. Diagnostics: none. Terminates: the value is a strict part. Source: https://dev.mysql.com/doc/refman/8.4/en/assignment-operators.html#operator_assign-value. Status: Implemented.
$query = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('SELECT a FROM t WHERE a = @n := 5');
[$query->statement->where->right->target->name->value, $query->statement->where->right->value->text] // => ['n', '5']Properties§
public UserVariable $targetpublic Scalar $valueMethods§
public function __construct(public UserVariable $target, public Scalar $value)Parameters
$target | UserVariable | The variable assigned to |
$value | Scalar | The assigned expression |
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives the target and the value; the assignment has the facts of the value.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 4
- method-call Derivation::scalar() line 50
- method-call Operands::single() line 51
- new Operands line 51
- new ScalarFact line 53
public function render(Output $out): voidWrites the target, the assignment operator and the value.
Parameters
$out | Output |
Calls 1
- method-call Output::node() line 61
Test cases 8§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 3
Other tests reaching this symbol 5
VariableRuleTest::testAssignmentLowersAnAssignmentInsideAnExpressioncallsPrecedenceTest::testAbsorbsTellsWhetherAFollowingOperatorBindsIntoTheRightEdgecallsPrecedenceTest::testTopIsTheLevelAtWhichAnExpressionStandscallsComparisonTest::testAVariableAssignmentAsLeftOperandIsRejectedcallsBetweenTest::testALowerBoundThatTakesTheAndIsRejectedcalls