packages/sql-semantics-sqlite/src/Statement/Schema/Problem/DuplicateColumn.php
1<?php
2
3declare(strict_types=1);
4
5namespace SqlSemantics\Platform\Sqlite\Statement\Schema\Problem;
6
7use SqlSemantics\Platform\Sqlite\Model\Statement\Fact\Diagnostic;
8use SqlSemantics\Platform\Sqlite\Model\Statement\Identifier\Name;
9use SqlSemantics\Platform\Sqlite\Model\Statement\Snapshot;
10
11/**
12 * A column name a table would have twice.
13 *
14 * SQLite compares column names without regard to ASCII case and rejects the
15 * definition, the added column or the new column name with "duplicate column name".
16 * Source: https://sqlite.org/lang_createtable.html, https://sqlite.org/lang_altertable.html.
17 *
18 * @visibility public
19 * @example Reporting a repeated column name
20 * (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('CREATE TABLE t (a, A)') // throws \SqlSemantics\Platform\Sqlite\Model\Diagnostic\SemanticException: Column A is defined more than once.
21 */
22final class DuplicateColumn implements Diagnostic
23{
24 use Snapshot;
25
26 /**
27 * @param Name $column The repeated name as written at its later occurrence
28 */
29 public function __construct(public readonly Name $column)
30 {
31 }
32
33 /**
34 * Describes the problem.
35 */
36 public function message(): string
37 {
38 return 'Column ' . $this->column->value . ' is defined more than once.';
39 }
40}
41