classDoBlock
final class DoBlock
implements Statement
uses Snapshot
@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.
$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']new \SqlSemantics\Platform\PostgreSql\Statement\Utility\DoBlock([]) // throws \SqlSemantics\Platform\PostgreSql\Model\Diagnostic\InvalidConstructionProperties§
public non-empty-list<StringConstant|DoLanguage> $itemsMethods§
public function __construct(array<array-key, object> $items)Parameters
$items | array<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 noneCalls 3
- new InvalidConstruction line 53
- static-call Check::input() line 57
- function-call
array_is_listline 57
public function code(): ?StringConstantAnswers the code when exactly one code string is written.
Returns
Calls 1
- function-call
countline 73
public function language(): ?DoLanguageAnswers the language clause when exactly one is written; without one the server uses plpgsql.
Returns
Calls 1
- function-call
countline 88
public function deriveStatement(Derivation $derivation): voidReports a block without code and an item written twice.
Parameters
$derivation | Derivation |
Calls 4
- method-call Derivation::report() line 103
- new UtilityProblem line 103
- class-const UtilityProblemKind::RedundantOptions() line 103
- class-const UtilityProblemKind::NoInlineCode() line 105
public function render(Output $out): voidWrites the request.
Parameters
$out | Output |
Calls 2
- method-call Output::keyword() line 114
- method-call Output::node() line 116
Test cases 5§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.