final class VariableDeclaration
    implements Declaration, Relation
    uses Snapshot
Public API: explicitly declared with @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.

Reading the variables of a declarationdoctest
$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> $names
public TypeName $type
public CollationName|null $collation = null
public Scalar|null $default = null

Methods§

public function __construct(
    list<Name> $names,
    public TypeName $type,
    public CollationName|null $collation = null,
    public Scalar|null $default = null,
)

Parameters

$nameslist<Name>The variable names; at least one
$typeTypeNameThe declared type
$collationCollationName|nullThe COLLATE clause of the type
$defaultScalar|nullThe DEFAULT value
Calls 2
public function deriveRelation(Derivation $derivation, Environment $environment): RelationFact

Derives the default value and answers the row of the variables.

Parameters

$derivationDerivation
$environmentEnvironment
Calls 6
public function render(Output $out): void

Writes the declaration.

Parameters

$outOutput
Calls 6

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

Relations§

Instantiated in 2
Type checks 1
Type declarations 1