final class DoBlock
    implements Statement
    uses Snapshot
Public API: explicitly declared with @visibility public.

DO [LANGUAGE name] code: a request to run an anonymous code block.

Rule: PG-DO-001. Mirrors PostgreSQL's DoStmt, whose arguments are the code string and the language in the order written. The code is text of the procedural language, which the language handler reads when the command runs; it is opaque to SQL and kept as the decoded string. Diagnostics: a block without code, and code or a language written twice. Source: https://www.postgresql.org/docs/17/sql-do.html. Status: Implemented.

Reading the code of an anonymous blockdoctest
$operation = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('DO $$BEGIN NULL; END$$ LANGUAGE plpgsql');
    [$operation->statement->code()?->value, $operation->statement->language()?->name()] // => ['BEGIN NULL; END', 'plpgsql']
Refusing a block without itemsdoctest
new \SqlSemantics\Platform\PostgreSql\Statement\Utility\DoBlock([]) // throws \SqlSemantics\Platform\PostgreSql\Model\Diagnostic\InvalidConstruction

Properties§

public non-empty-list<StringConstant|DoLanguage> $items

Methods§

public function __construct(array<array-key, object> $items)

Parameters

$itemsarray<array-key, object>The code strings and language clauses in the order written; at least one

Throws

InvalidConstruction When an item is neither a string nor a language clause, or there is none
Calls 3
public function code(): ?StringConstant

Answers the code when exactly one code string is written.

Calls 1
public function language(): ?DoLanguage

Answers the language clause when exactly one is written; without one the server uses plpgsql.

Returns

Calls 1
public function deriveStatement(Derivation $derivation): void

Reports a block without code and an item written twice.

Parameters

$derivationDerivation
Calls 4
public function render(Output $out): void

Writes the request.

Parameters

$outOutput
Calls 2

Test cases 5§

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

Dedicated tests 4
Other tests reaching this symbol 1

Relations§

Instantiated in 1