classVariableDeclaration
final class VariableDeclaration
implements Declaration, Relation
uses Snapshot
@visibility public.DECLARE of local variables: one or more names of one type with an optional default value.
Rule: MYSQL-PROGRAM-VARIABLES-001. The declaration is the relation whose row holds one position per declared name: a name used as a value in the block resolves to that position. Every position has the declared type and can be NULL, since a variable without DEFAULT starts as NULL and any variable can be assigned NULL. The default value is derived in the scope before the declaration. Terminates: one pass over the names. Source: https://dev.mysql.com/doc/refman/8.4/en/declare-local-variable.html. Status: Implemented.
$create = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('CREATE PROCEDURE p() BEGIN DECLARE a, b INT DEFAULT 0; END');
$declaration = $create->statement->body->declarations[0];
[count($declaration->names), $declaration->type->name(), $declaration->default !== null] // => [2, 'INT', true]Properties§
public non-empty-list<Name> $namespublic TypeName $typepublic CollationName|null $collation = nullpublic Scalar|null $default = nullMethods§
public function __construct(
list<Name> $names,
public TypeName $type,
public CollationName|null $collation = null,
public Scalar|null $default = null,
)Parameters
$names | list<Name> | The variable names; at least one |
$type | TypeName | The declared type |
$collation | CollationName|null | The COLLATE clause of the type |
$default | Scalar|null | The DEFAULT value |
Calls 2
- static-call Check::listOf() line 60
- class-const Name::class() line 60
public function deriveRelation(Derivation $derivation, Environment $environment): RelationFactDerives the default value and answers the row of the variables.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 6
- method-call Derivation::scalar() line 69
- new OutputSlot line 73
- new Known line 73
- class-const Nullability::Nullable() line 73
- new RelationFact line 76
- new RowShape line 76
public function render(Output $out): voidWrites the declaration.
Parameters
$out | Output |
Calls 6
- method-call Output::keyword() line 84
- method-call Output::symbol() line 87
- method-call Output::name() line 89
- class-const NameUse::Identifier() line 89
- method-call ProgramNames::type() line 91
- new ProgramNames line 91
Test cases 12§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 2
Other tests reaching this symbol 10
ParameterRuleTest::testDeclaredLowersATypeWithItsCollationcallsBlockRuleTest::testBlockLowersAnUnlabeledBlockcallsBlockRuleTest::testDeclarationLowersAConditionAndAHandlercallsBlockRuleTest::testDeclarationLowersAVariableWithItsCollationAndDefaultcallsBlockRuleTest::testInitialLowersTheDefaultClausecallsBlockRuleTest::testNamesLowersTheDeclaredAndTheFetchedNamescallsSequenceTest::testItemsAnswersTheMembersInSourceOrdercallsReturnSearchTest::providerFoundIsFalseWithoutReturncallsDeclarationTest::providerImplementationsAreTheFourDeclarationscallsProgramStatementTest::providerDeriveProgramIsImplementedByTheProgramStatementClassescalls
Relations§
Instantiated in 2
- new SqlSemantics\Platform\MySql\Lowering\Routine\Program\BlockRule::declaration() packages/sql-semantics-mysql/src/Lowering/Routine/Program/BlockRule.php:101
- new SqlSemantics\Platform\MySql\Lowering\Routine\Program\BlockRule::declaration() packages/sql-semantics-mysql/src/Lowering/Routine/Program/BlockRule.php:105