classLock
final class Lock
implements Statement
uses Snapshot
Public API: explicitly declared with
@visibility public.LOCK [TABLE] name [, ...] [IN mode MODE] [NOWAIT]: a request to lock tables for the current transaction.
Rule: PG-LOCK-001. Mirrors PostgreSQL's LockStmt (relations, mode, nowait). Without a mode the strongest one, ACCESS EXCLUSIVE, is taken; a written mode is kept as written. The word TABLE has no effect and is not kept. Facts: each table is resolved; only tables and views can be locked (RangeVarCallbackForLockTable; PG-RELATION-KIND-001). Source: https://www.postgresql.org/docs/17/sql-lock.html. Status: Implemented.
$operation = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('LOCK TABLE ONLY a, b NOWAIT');
[$operation->statement->mode, $operation->statement->effectiveMode(), $operation->toString()] // => [null, \SqlSemantics\Platform\PostgreSql\Statement\Utility\Maintenance\LockMode::AccessExclusive, 'LOCK ONLY a, b NOWAIT']new \SqlSemantics\Platform\PostgreSql\Statement\Utility\Maintenance\Lock([]) // throws \SqlSemantics\Platform\PostgreSql\Model\Diagnostic\InvalidConstructionProperties§
public non-empty-list<RelationReference> $tablespublic LockMode|null $mode = nullpublic bool $nowait = falseMethods§
public function __construct(
list<RelationReference> $tables,
public LockMode|null $mode = null,
public bool $nowait = false,
)Parameters
$tables | list<RelationReference> | The tables; at least one |
$mode | LockMode|null | The lock mode, when written |
$nowait | bool | Whether the command fails instead of waiting for a conflicting lock |
Calls 2
- static-call Check::listOf() line 51
- class-const RelationReference::class() line 51
public function effectiveMode(): LockModeAnswers the mode the command takes: the written one, or ACCESS EXCLUSIVE.
Returns
Calls 1
- class-const LockMode::AccessExclusive() line 59
public function deriveStatement(Derivation $derivation): voidResolves each table.
Parameters
$derivation | Derivation |
Calls 9
- new RelationKinds line 67
- method-call RelationKinds::of() line 69
- method-call Derivation::target() line 69
- method-call Targets::resolve() line 69
- new Targets line 69
- method-call RelationKinds::require() line 70
- class-const RelationKind::BaseTable() line 70
- class-const RelationKind::View() line 70
- class-const KindRule::LockRelation() line 70
public function render(Output $out): voidWrites the request.
Parameters
$out | Output |
Calls 2
- method-call Output::keyword() line 79
- function-call
explodeline 81
Test cases 3§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.