classTablePrimaryKey
final class TablePrimaryKey
implements TableConstraint
uses Snapshot
@visibility public.A PRIMARY KEY table constraint.
Rule: SQLITE-TABLE-PRIMARY-KEY-001. The grammar writes the key terms as ordering terms, so any expression parses; SQLite accepts column names only, each optionally with a collation and a sort order ("expressions prohibited
- in PRIMARY KEY and UNIQUE constraints"). A column name is an identifier, a
double-quoted word or a string literal (LiteralColumn; a plain string literal term is refused at construction, SQLITE-KEY-TERM-001). Each term is derived where the columns and the row identifier of the table are visible. Unlike the column constraint, a single-column key of declared type INTEGER is the row identifier whatever sort order is written. AUTOINCREMENT is written inside the parentheses after the last term. Source: https://sqlite.org/lang_createtable.html#the_primary_key, https://sqlite.org/lang_createtable.html#rowid. Status: Implemented.
$create = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('CREATE TABLE t (a, b, PRIMARY KEY (a, b DESC) ON CONFLICT ROLLBACK)');
$key = $create->statement->constraints[0]->items[0];
[count($key->terms), $key->terms[1]->direction?->value, $key->conflict?->value] // => [2, 'DESC', 'ROLLBACK']Properties§
public non-empty-list<SortTerm> $termspublic ConflictResolution|null $conflict = nullpublic bool $autoincrement = falseMethods§
public function __construct(
list<SortTerm> $terms,
public ConflictResolution|null $conflict = null,
public bool $autoincrement = false,
)Parameters
$terms | list<SortTerm> | The key terms in written order; at least one |
$conflict | ConflictResolution|null | The written ON CONFLICT resolution |
$autoincrement | bool | Whether AUTOINCREMENT is written after the last key term |
Calls 5
- static-call Check::listOf() line 56
- class-const SortTerm::class() line 56
- static-call Check::input() line 58
- method-call KeyTerms::string() line 58
- new KeyTerms line 58
public function deriveConstraint(Derivation $derivation, ConstraintScope $scope): voidDerives each term where the columns of the table are visible and reports a term that is no column name.
Parameters
$derivation | Derivation | |
$scope | ConstraintScope |
Calls 6
- method-call Derivation::scalar() line 68
- method-call KeyTerms::reference() line 69
- new KeyTerms line 69
- method-call Derivation::report() line 70
- new PrimaryKeyProblem line 70
- class-const PrimaryKeyFlaw::ExpressionTerm() line 70
public function render(Output $out): voidWrites the clause.
Parameters
$out | Output |
Calls 2
- method-call Output::keyword() line 80
- method-call Output::symbol() line 84
Test cases 9§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 3
Other tests reaching this symbol 6
KeyTermRuleTest::testKeyTermsWrapAStringUnderAnyParenthesesAndCollationscallsTableConstraintRuleTest::testConstraintLowersEveryKindOfTableConstraintcallsPrimaryKeyRuleTest::testTableKeyListsTheColumnsOfACompositeKeyInKeyOrdercallsPrimaryKeyRuleTest::testTableKeyMakesASingleIntegerColumnTheRowidWhateverItsSortOrdercallsLiteralColumnTest::testDeriveScalarResolvesTheColumnOfTheTableBeingDefinedcallsTableConstraintTest::testDeriveConstraintDerivesTheOperandsOfEachConstraintcalls