packages/sql-semantics-sqlite/src/Statement/Schema/Problem/UnknownTableOption.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\Schema\Table\TableOption;
10
11/**
12 * A table option that is neither WITHOUT ROWID nor STRICT.
13 *
14 * The grammar accepts any name as an option; SQLite compares the written text
15 * with `rowid` and `strict` and rejects every other word, a quoted `"rowid"`
16 * included, with "unknown table option".
17 * Source: https://sqlite.org/syntax/table-options.html.
18 *
19 * @visibility public
20 * @example Reporting an unknown option
21 * (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('CREATE TABLE t (a) WITHOUT oid') // throws \SqlSemantics\Platform\Sqlite\Model\Diagnostic\SemanticException: Table option oid is unknown.
22 */
23final class UnknownTableOption implements Diagnostic
24{
25 use Snapshot;
26
27 /**
28 * @param TableOption $option The option SQLite does not know
29 */
30 public function __construct(public readonly TableOption $option)
31 {
32 }
33
34 /**
35 * Describes the problem.
36 */
37 public function message(): string
38 {
39 return 'Table option ' . $this->option->word->spelling() . ' is unknown.';
40 }
41}
42