final class RowConstraints

Refuses a row the table would not have accepted.

Nothing is inserted, so nothing checks these but this. A statement whose rows the database would have rejected has to be rejected here too, or the shadow ends up describing a state the database could never have been in.

A key with a null in it is left alone: SQL says such a key collides with nothing, not even with another row carrying the same nulls.

Type Aliases§

Row = import from TableDefinition
RowValue = import from TableDefinition

Methods§

public function assertNoNullWhereNoneIsAllowed(Row $row): void

Refuses a row that leaves null in a column the table will not take one in.

A column the row does not carry at all is not a null: the database would put its default there.

Parameters

$rowRowRow that would be written

Throws

NotNullViolationException When a column that cannot be null is written as null
Test cases 3
Called from 2
Calls 2
public function assertNoDuplicateUniqueKey(
    Row $row,
    array<int, Row> $existingRows,
    list<string> $identityColumns = [],
): void

Refuses a row that would collide with one already there on a unique key.

A row being changed does not collide with itself, so the row already there that is this row is left out. Which columns say so is passed in, because an insert has no such row and an update does.

Parameters

$rowRowRow that would be written
$existingRowsarray<int, Row>Rows already there
$identityColumnslist<string>Columns that say a row already there is this row

Throws

DuplicateKeyException When the row collides on one of the table's unique keys
Test cases 3
Called from 2
Calls 4
public function carriesNullIn(Row $row, list<string> $columns): bool
public function agreeOn(Row $row, Row $existing, list<string> $columns): bool

Reports whether two rows carry the same values in the named columns.

A row that does not carry one of them agrees with nothing on it.

Parameters

$rowRowRow that would be written
$existingRowRow already there
$columnslist<string>Columns of one key

Returns

bool True when both carry every column identically
Test cases 4
Called from 2
public function keyValues(Row $row, list<string> $columns): Row

Reads the values a row carries on one key, under the column names.

Parameters

$rowRowRow to read
$columnslist<string>Columns of one key

Returns

Row Column => the value it carries, or null where it carries none
Test cases 2
Called from 1

Private surface 3§

Implementation details, listed for orientation only.

private TableDefinition|null $definition
private string $tableName
private string $sql

Test cases 22§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 12
Other tests reaching this symbol 10

Relations§

Instantiated in 2
Method calls 4
Type declarations 2