classPrepare
final class Prepare
implements Statement
uses Snapshot
Public API: explicitly declared with
@visibility public.PREPARE: a statement stored under a name in the session, with the types of its parameters.
Mirrors PostgreSQL's PrepareStmt (name, argtypes, query). Rule: PG-PREPARE-001. The statement is derived as a nested query in an environment that sees only the declared parameter types (PG-PREPARE-PARAMETERS-001), so $n has the declared type of its position; preparing it returns no rows and declares no relation. A selection with INTO is admitted as the first selection of a query statement only (PG-PLACEMENT-001). Source: https://www.postgresql.org/docs/17/sql-prepare.html. Status: Implemented.
$prepare = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('PREPARE p (integer) AS SELECT $1');
[$prepare->statement->name->value, count($prepare->statement->parameters->types), $prepare->toString()] // => ['p', 1, 'PREPARE p (INTEGER) AS SELECT $1']Properties§
public Name $namepublic PreparedParameters|null $parameterspublic Query $statementMethods§
public function __construct(
public Name $name,
public PreparedParameters|null $parameters,
public Query $statement,
)Parameters
$name | Name | The name of the prepared statement |
$parameters | PreparedParameters|null | The declared parameter types; null when none is written |
$statement | Query | The statement prepared: a query statement or a data-modifying statement |
Throws
InvalidConstruction When the statement is of another kindCalls 3
- static-call Check::input() line 52
- method-call Sources::statement() line 52
- new Sources line 52
public function deriveStatement(Derivation $derivation): voidDerives the types and the statement.
Parameters
$derivation | Derivation |
Calls 11
- method-call Derivation::environment() line 60
- method-call Derivation::relation() line 62
- new Environment line 63
- new VisibleRelation line 63
- method-call Derivation::query() line 65
- new Placement line 66
- method-call Placement::values() line 67
- method-call Placement::into() line 68
- method-call QueryRoots::first() line 68
- new QueryRoots line 68
- method-call Placement::modifying() line 69
public function render(Output $out): voidWrites the statement.
Parameters
$out | Output |
Calls 3
- method-call Output::keyword() line 77
- class-const NameUse::Column() line 77
- method-call Output::node() line 78
Test cases 8§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 1
PrepareTestcalls
Other tests reaching this symbol 7
ManipulationsTest::testPreparableLowersADataModifyingStatementcallsManipulationsTest::testStatementRoutesEveryStatementOfTheFamilycallsPreparedRuleTest::testPrepareLowersTheTypescallsParameterDeclarationsTest::testInfersUndeclaredInPrepareOnlycallsPreparedParametersTest::testDeriveRelationAnswersOneUnnamedSlotPerTypecallsPreparedParametersTest::testDeriveRelationTypesTheParametersOfThePreparedStatementcallsPreparedParametersTest::testInfersUndeclaredIsTruecalls