packages/sql-semantics-mysql/src/Statement/Account/Problem/UnknownGrantColumn.php
1<?php
2
3declare(strict_types=1);
4
5namespace SqlSemantics\Platform\MySql\Statement\Account\Problem;
6
7use SqlSemantics\Platform\MySql\Model\Statement\Fact\Diagnostic;
8use SqlSemantics\Platform\MySql\Model\Statement\Identifier\Name;
9use SqlSemantics\Platform\MySql\Model\Statement\Identifier\QualifiedName;
10use SqlSemantics\Platform\MySql\Model\Statement\Snapshot;
11
12/**
13 * A column of a column privilege that the completely declared table of GRANT does not have.
14 *
15 * The server rejects the statement with ER_BAD_FIELD_ERROR
16 * (mysql_table_grant). REVOKE does not check the columns.
17 * Source: https://dev.mysql.com/doc/refman/8.4/en/grant.html#grant-column-privileges.
18 *
19 * @visibility public
20 * @example Describing the problem
21 * (new \SqlSemantics\Platform\MySql\Statement\Account\Problem\UnknownGrantColumn(new \SqlSemantics\Platform\MySql\Model\Statement\Identifier\Name('c'), new \SqlSemantics\Platform\MySql\Model\Statement\Identifier\QualifiedName(new \SqlSemantics\Platform\MySql\Model\Statement\Identifier\Name('t'))))->message() // => 'Column c does not exist in table t.'
22 */
23final class UnknownGrantColumn implements Diagnostic
24{
25 use Snapshot;
26
27 /**
28 * @param Name $column The column as written
29 * @param QualifiedName $table The table as written
30 */
31 public function __construct(public readonly Name $column, public readonly QualifiedName $table)
32 {
33 }
34
35 /**
36 * Describes the problem.
37 */
38 public function message(): string
39 {
40 return 'Column ' . $this->column->value . ' does not exist in table ' . ($this->table->schema === null ? '' : $this->table->schema->value . '.') . $this->table->name->value . '.';
41 }
42}
43