packages/sql-semantics-sqlite/src/Statement/Schema/Problem/UnknownStorage.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\Snapshot;
9use SqlSemantics\Platform\Sqlite\Statement\Lexical\Word;
10
11/**
12 * A word after the expression of a generated column that is neither VIRTUAL nor STORED.
13 *
14 * The grammar accepts any identifier; SQLite compares the written text with
15 * `virtual` and `stored` and rejects every other word, a quoted one included.
16 * Source: https://sqlite.org/gencol.html.
17 *
18 * @visibility public
19 * @example Reporting an unknown storage word
20 * (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('CREATE TABLE t (a, b AS (a) PERSISTED)') // throws \SqlSemantics\Platform\Sqlite\Model\Diagnostic\SemanticException: Generated column storage PERSISTED is neither VIRTUAL nor STORED.
21 */
22final class UnknownStorage implements Diagnostic
23{
24 use Snapshot;
25
26 /**
27 * @param Word $word The written word
28 */
29 public function __construct(public readonly Word $word)
30 {
31 }
32
33 /**
34 * Describes the problem.
35 */
36 public function message(): string
37 {
38 return 'Generated column storage ' . $this->word->spelling() . ' is neither VIRTUAL nor STORED.';
39 }
40}
41