classQueryStatement
final class QueryStatement
implements Statement, Query
uses Snapshot
@visibility public.INTO and locking clauses written after a set operation, a parenthesized query or another query that is not a single query block.
After a single query block, also one with a WITH clause, the clauses belong to the block, so such a query is refused here. INTO after the query is written before the locking clauses or after them.
Rule: MYSQL-QUERY-STATEMENT-001. The rows are those of the query; the INTO targets and the locking clauses are derived by MYSQL-TAIL-FACTS-001. Source: https://dev.mysql.com/doc/refman/8.4/en/select.html, https://dev.mysql.com/doc/refman/8.4/en/select-into.html. Status: Implemented.
$query = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('SELECT a FROM t UNION SELECT b FROM u INTO @x');
$query->statement->into->targets[0]->name->value // => 'x'$one = new \SqlSemantics\Platform\MySql\Statement\Query\Select([], [new \SqlSemantics\Platform\MySql\Statement\Query\SelectExpression(new \SqlSemantics\Platform\MySql\Statement\Literal\NumberLiteral('1'))]);
new \SqlSemantics\Platform\MySql\Statement\Query\QueryStatement(new \SqlSemantics\Platform\MySql\Statement\Query\ParenthesizedQuery($one)) // throws \SqlSemantics\Platform\MySql\Model\Diagnostic\InvalidConstructionProperties§
public list<LockingClause> $lockingpublic Query $querypublic IntoDestination|null $into = nullpublic IntoPosition|null $intoPosition = nullMethods§
public function __construct(
public Query $query,
list<LockingClause> $locking = [],
public IntoDestination|null $into = null,
public IntoPosition|null $intoPosition = null,
)Parameters
$query | Query | The query the clauses follow |
$locking | list<LockingClause> | The locking clauses |
$into | IntoDestination|null | The INTO destination |
$intoPosition | IntoPosition|null | Where INTO is written: after the query or after the locking clauses; given exactly when there is a destination |
Calls 5
- static-call Check::listOf() line 58
- class-const LockingClause::class() line 58
- static-call Check::input() line 59
- class-const IntoPosition::AfterItems() line 61
- class-const IntoPosition::AfterLocking() line 62
public function deriveStatement(Derivation $derivation): voidDerives the query as a statement root and records its rows as the output.
Parameters
$derivation | Derivation |
Calls 3
- method-call Derivation::output() line 72
- method-call Derivation::query() line 72
- method-call Derivation::environment() line 72
public function deriveQuery(Derivation $derivation, Environment $outer): QueryFactDerives the query, the INTO targets and the locking clauses.
Parameters
$derivation | Derivation | |
$outer | Environment |
Returns
Calls 3
- method-call Derivation::query() line 80
- method-call TailFacts::derive() line 81
- new TailFacts line 81
public function render(Output $out): voidWrites the query and the clauses in written order.
Parameters
$out | Output |
Calls 4
- method-call Output::node() line 91
- class-const IntoPosition::AfterQuery() line 92
- method-call Output::keyword() line 93
- class-const IntoPosition::AfterLocking() line 98
Test cases 8§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 5
QueryStatementTest::testAnIntoAfterTheSelectListIsRejectedcallsQueryStatementTest::testDeriveQueryDerivesTheTargetsAndReportsTheirCountcallsQueryStatementTest::testDeriveStatementRecordsTheRowsOfTheQuerycallsQueryStatementTest::testRenderWritesTheClausesInWrittenOrdercallsQueryStatementTest::testTheClausesOfASingleBlockAreRejectedcalls
Other tests reaching this symbol 3
Relations§
Instantiated in 1
Type checks 7
- instanceof SqlSemantics\Platform\MySql\Rules\Dml\GeneratedWrites::valueRows() packages/sql-semantics-mysql/src/Rules/Dml/GeneratedWrites.php:122
- instanceof SqlSemantics\Platform\MySql\Rules\Routine\ProgramRestrictions::into() packages/sql-semantics-mysql/src/Rules/Routine/ProgramRestrictions.php:151
- instanceof SqlSemantics\Platform\MySql\Rules\TableDefinition\ViewColumns::block() packages/sql-semantics-mysql/src/Rules/TableDefinition/ViewColumns.php:133
- instanceof SqlSemantics\Platform\MySql\Statement\Query\QueryExpression::__construct() packages/sql-semantics-mysql/src/Statement/Query/QueryExpression.php:66
- instanceof SqlSemantics\Platform\MySql\Statement\Query\Set\LeadingUnion::__construct() packages/sql-semantics-mysql/src/Statement/Query/Set/LeadingUnion.php:62
- instanceof SqlSemantics\Platform\MySql\Statement\Query\Set\OrderedSetOperation::__construct() packages/sql-semantics-mysql/src/Statement/Query/Set/OrderedSetOperation.php:85
- instanceof SqlSemantics\Platform\MySql\Statement\Query\Set\SetOperation::__construct() packages/sql-semantics-mysql/src/Statement/Query/Set/SetOperation.php:61