classOperation
final class Operation
implements Query
uses Snapshot
@visibility public.One analyzed statement: its structure, the facts derived against a fixed context, and its SQL.
The constructor is the only way to obtain an operation and it is a checking boundary. It audits the structure, derives every fact, renders the SQL, and confirms that the rendered SQL has the same structure. Nothing is filled in afterwards and nothing can be changed. A different statement is a new operation built from explicit inputs or from newly analyzed SQL; it has no guaranteed relation to this one.
$semantics = new \SqlSemantics\Platform\MySql\Semantics();
$bar = $semantics->analyze('CREATE TABLE bar (foo INTEGER, baz TEXT)');
$query = $semantics->analyze('SELECT foo FROM bar', [$bar]);
[$query->field('foo')->column() === $bar->declarations()[0]->columns[0], $query->toString()] // => [true, 'SELECT foo FROM bar']$semantics = new \SqlSemantics\Platform\MySql\Semantics();
$query = $semantics->analyze('SELECT foo FROM bar WHERE foo > 1');
$other = new \SqlSemantics\Platform\MySql\Model\Statement\Operation($query->context, $semantics->analyze('SELECT baz FROM bar')->statement);
$other->toString() // => 'SELECT baz FROM bar'Properties§
public Facts $factspublic AnalysisContext $contextpublic Statement $statementMethods§
public function __construct(public AnalysisContext $context, public Statement $statement)Derives and checks a new root from a context and an explicit statement structure.
A structure outside the closed value domain, a node shared between two positions, or a context of another profile is refused as an invalid construction. A missing rule or a failed correspondence check is a defect of the library and discards the candidate.
Parameters
$context | AnalysisContext | The fixed profile and declaration snapshot |
$statement | Statement | The requested statement |
Calls 2
- method-call Publication::establish() line 65
- new Publication line 65
public function toString(): stringAnswers the SQL rendered from the structure and confirmed to correspond to it; never the analyzed text.
Returns
stringTest cases 5
SelectExpressionTest::testRenderWritesAnItemBuiltWithoutLayoutCanonicallycallsSelectTest::testRenderBuildsSqlFromAnExplicitStructurecallsLeadingUnionTest::testRenderNeedsMySql5ForTheFormAndMySql56ForAnOwnLimitcallsSystemVariableTest::testRenderBuildsSqlFromAnExplicitStructurecallsUserVariableTest::testRenderBuildsSqlFromAnExplicitStructurecalls
public function profile(): LanguageProfileAnswers the fixed language profile the operation was built under.
Returns
public function declarations(): list<Table>Answers the relation declarations the statement provides to a context.
Returns
list<Table>public function shape(): ?RowShapeAnswers the shape of the rows the statement returns, or null when it returns none.
Returns
public function fields(): ?FieldsAnswers the complete ordered output fields, or null when the statement returns no rows or its shape is open.
Returns
public function field(string|int $key): FieldAnswers the one field at a position or with a name.
This is a convenience for the unique case; use lookupField() to tell absent, ambiguous and dependent lookups apart.
Parameters
$key | string|int |
Returns
Throws
InvalidConstruction When no field or more than one field answers the keyTest cases 2
Calls 4
- function-call
is_intline 122 - method-call Operation::fields() line 123
- static-call Check::input() line 124
- method-call Operation::lookupField() line 128
public function lookupField(string $name): FieldLookupLooks an output field up by name, distinguishing unique, absent, ambiguous and dependent results.
Parameters
$name | string |
Returns
Throws
InvalidConstruction When the statement returns no rowsCalled from 1
Calls 1
- static-call Check::input() line 141
public function inputRelation(): ?RelationAnswers the input relation structure of a selection, or null when there is none.
Returns
Called from 1
Calls 1
- method-call Statement::input() line 151
public function singleNamedInput(): NamedRelationAnswers the input when it is exactly one plainly named relation.
Returns
Throws
InvalidConstruction When the input is a join, a derived relation, several relations, or absentCalls 2
- method-call Operation::inputRelation() line 161
- static-call Check::input() line 162
Private surface 1§
Implementation details, listed for orientation only.
private string $sqlTest cases 29§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Other tests reaching this symbol 29
SetFactsTest::testLeadingRefusesAnOwnLimitOnMySql57callsSourceSettingsTest::testOptionRejectsAnOptionOfALaterReleasecallsSemanticsTest::testAnalyzeReturnsTheDatabaseOperationThroughTheCommonInterfacecallsStringLiteralTest::testDeriveScalarRejectsALiteralSpelledUnderTheOtherEscapeRulecallsTemporalLiteralTest::testDeriveScalarRejectsALiteralSpelledUnderTheOtherEscapeRulecallsSelectExpressionTest::testRenderWritesAnItemBuiltWithoutLayoutCanonicallycallsSelectTest::testANodeUsedAtTwoPositionsIsRejectedcallsSelectTest::testAStringLiteralUnderAnotherEscapeRuleIsRejectedcallsSelectTest::testDeriveQueryRefusesALateOrderingBefore56callsSelectTest::testDeriveStatementRefusesALateOrderingAtTheTopcallsSelectTest::testRenderBuildsSqlFromAnExplicitStructurecallsLeadingUnionTest::testRenderNeedsMySql5ForTheFormAndMySql56ForAnOwnLimitcallsOrderedSetOperationTest::testDeriveQueryNeedsMySql56callsStartGroupReplicationTest::testDeriveStatementRejectsMySql56callsStopGroupReplicationTest::testDeriveStatementRejectsMySql56callsStartReplicaTest::testDeriveStatementRejectsSlaveAfterItsRemovalcallsStopReplicaTest::testDeriveStatementRejectsAChannelOfMySql56callsResetPersistTest::testDeriveStatementRejectsMySql57callsResetQueryCacheTest::testDeriveTargetRejectsReleasesWithoutAQueryCachecallsResetReplicaTest::testDeriveTargetRejectsTheVocabularyOfAnotherReleasecallsChangeReplicationSourceTest::testDeriveStatementRejectsAnOptionOfALaterReleasecallsChangeReplicationSourceTest::testDeriveStatementRejectsTheVocabularyOfAnotherReleasecallsXaCommitTest::testDeriveStatementRefusesAFormatAboveTheSignedRangeAfterMySql56callsXaEndTest::testDeriveStatementRefusesAFormatAboveTheSignedRangeAfterMySql56callsXaPrepareTest::testDeriveStatementRefusesAFormatAboveTheSignedRangeAfterMySql56callsXaRollbackTest::testDeriveStatementRefusesAFormatAboveTheSignedRangeAfterMySql56callsXaStartTest::testDeriveStatementRefusesAFormatAboveTheSignedRangeAfterMySql56callsSystemVariableTest::testRenderBuildsSqlFromAnExplicitStructurecallsUserVariableTest::testRenderBuildsSqlFromAnExplicitStructurecalls