classOutputOrdinal
final class OutputOrdinal
implements Scalar
uses Snapshot
@visibility public.An ORDER BY or GROUP BY term that is an integer constant: a request for the result column at that position.
This is a different request from the constant it is written as: SQLite does not evaluate the constant but sorts or groups by the result column it counts to.
Rule: SQLITE-OUTPUT-ORDINAL-001. The constant is one that SQLITE-ORDINAL-001 recognises. A position between 1 and the number of result columns denotes that result column and has its facts; any other position is out of range. When the result columns are not all known, a position beyond the known ones depends on the missing inputs. Source: https://sqlite.org/lang_select.html#the_order_by_clause. Status: Implemented.
$query = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze("SELECT 'x' AS a, 2 AS b ORDER BY 2");
$query->facts->scalar($query->statement->orderBy[0]->expression)->resolution->field->name->value // => 'b'new \SqlSemantics\Platform\Sqlite\Statement\Query\Ordering\OutputOrdinal(new \SqlSemantics\Platform\Sqlite\Statement\Expression\Literal\TextLiteral('1')) // throws \SqlSemantics\Platform\Sqlite\Model\Diagnostic\InvalidConstructionProperties§
public Scalar $constantMethods§
public function __construct(public Scalar $constant)Parameters
$constant | Scalar | The integer constant as written |
Calls 3
- static-call Check::input() line 51
- method-call Ordinals::value() line 51
- new Ordinals line 51
public function position(): intAnswers the position the constant counts to; the first result column is 1.
Returns
intTest cases 1
Called from 1
Calls 2
- method-call Ordinals::value() line 59
- new Ordinals line 59
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives the constant and the result column the position denotes among the result columns the environment lists.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 10
- method-call Derivation::scalar() line 67
- method-call OutputOrdinal::position() line 68
- new ScalarFact line 71
- new AliasTarget line 71
- function-call
array_pushline 76 - new Dependent line 79
- class-const Nullability::Dependent() line 79
- new OrdinalOutOfRange line 81
- function-call
countline 81 - new Invalid line 83
public function render(Output $out): voidTest cases 10§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 5
OutputOrdinalTest::testDeriveScalarAlsoRecordsTheConstantcallsOutputOrdinalTest::testDeriveScalarDenotesTheResultColumnAtThePositioncallsOutputOrdinalTest::testPositionCountsFromOnecallsOutputOrdinalTest::testRenderRefusesAnExpressionThatIsNoIntegerConstantcallsOutputOrdinalTest::testRenderRefusesAnIntegerBeyondThirtyTwoBitscalls
Other tests reaching this symbol 5
SelectRuleTest::testBodyLowersACompoundQueryWithItsArmsInOrderAndTheTrailingOrderByAndLimitcallsSelectRuleTest::testGroupsTurnsAnIntegerConstantIntoAResultColumnPositioncallsSortRuleTest::testTermsTreatsAnIntegerAsAResultColumnPositionOnlyInTheOrderByOfAQuerycallsSortScopesTest::testDeriveResolvesAnOrdinalAgainstTheProjectionAndReportsARowValuecallsSelectTest::testRenderWritesANewlyBuiltSelectioncalls
Relations§
Instantiated in 2
Type checks 3
- instanceof SqlSemantics\Platform\Sqlite\Rules\Query\SortScopes::derive() packages/sql-semantics-sqlite/src/Rules/Query/SortScopes.php:58
- instanceof SqlSemantics\Platform\Sqlite\Statement\Query\Compound::__construct() packages/sql-semantics-sqlite/src/Statement/Query/Compound.php:69
- instanceof SqlSemantics\Platform\Sqlite\Statement\Query\Select::__construct() packages/sql-semantics-sqlite/src/Statement/Query/Select.php:95