classBareName
final class BareName
implements Scalar
uses Snapshot
@visibility public.A bare name written as the value of a variable assignment in SET, such as TRADITIONAL in SET sql_mode = TRADITIONAL.
Rule: MYSQL-SET-WORD-001. When the assigned variable is a system variable, the server does not resolve the name as a column: it assigns the text of the last name part (b for a.b) as a string. Facts: assigned to a system variable (@@x, or a name with a scope keyword), the value is a known non-NULL VARCHAR; assigned to a name without a scope, which inside a stored program can be a declared variable whose value is an expression, it depends on the declarations of the enclosing program (ProgramVariable). In a trigger body NEW.x and OLD.x are a column of the row whatever the variable (the parser makes them Item_trigger_field, which is not turned into text), so they resolve as a column name does (MYSQL-COLUMN-LOOKUP-001). The qualifiers are kept and written back. Terminates: no child is derived. Source: https://dev.mysql.com/doc/refman/8.4/en/set-variable.html, set_var::set_var in sql/set_var.cc ("If the set value is a field, change
- it to a string to allow things like SET table_type=MYISAM;").
Status: Implemented.
$set = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('SET @@sql_mode = TRADITIONAL');
[$set->statement->items[0]->value->word->value, $set->facts->scalar($set->statement->items[0]->value)->type->descriptor->name()] // => ['TRADITIONAL', 'VARCHAR']Properties§
public Name $wordpublic QualifiedName|null $qualifier = nullpublic bool $system = trueMethods§
public function __construct(
public Name $word,
public QualifiedName|null $qualifier = null,
public bool $system = true,
)Parameters
$word | Name | The last name part, whose text is the value |
$qualifier | QualifiedName|null | The name parts written before it |
$system | bool | Whether the assigned variable is known to be a system variable |
Calls 1
- static-call Check::input() line 61
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives a known string for a system variable, and the dependence on the enclosing program otherwise.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 11
- new ColumnResolver line 69
- method-call ColumnResolver::row() line 70
- method-call ColumnResolver::fact() line 71
- new ScalarFact line 74
- new Known line 74
- new Character line 74
- class-const CharacterKind::VarChar() line 74
- class-const Nullability::NotNull() line 74
- new Dependent line 77
- new ProgramVariable line 77
- class-const Nullability::Dependent() line 77
public function render(Output $out): voidWrites the name parts separated by dots.
Parameters
$out | Output |
Calls 3
- method-call Output::name() line 86
- class-const NameUse::Qualifier() line 86
- class-const NameUse::Column() line 91
Test cases 7§
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 5
ValueRuleTest::testWordLowersABareNamecallsNameAssignmentTest::testDeriveItemLeavesAnUnscopedWordToTheProgramcallsNameAssignmentTest::testRefusesAWordThatContradictsTheScopecallsSystemAssignmentTest::testDeriveItemDerivesTheVariableAndTheValuecallsSystemAssignmentTest::testRefusesAnUnresolvedWordcalls
Relations§
Instantiated in 1
Type checks 2
- instanceof SqlSemantics\Platform\MySql\Statement\Utility\Set\NameAssignment::__construct() packages/sql-semantics-mysql/src/Statement/Utility/Set/NameAssignment.php:53
- instanceof SqlSemantics\Platform\MySql\Statement\Utility\Set\SystemAssignment::__construct() packages/sql-semantics-mysql/src/Statement/Utility/Set/SystemAssignment.php:43