classResultColumn
final class ResultColumn
implements Node
uses Snapshot
@visibility public.One projected expression of a selection or of a RETURNING clause with its optional alias.
SQLite names a result column without an alias after the text of its expression from its first token to the start of the next one (SQLITE-RESULT-NAME-001), so such a column keeps that text as a layout (CORE-SPELLING-001): one spelling per token the expression renders, with the comments and whitespace written between them, and the trivia after the expression when it holds a comment. The expression is written in that spelling, so the rendered SQL names the column as the analyzed SQL did. A layout is kept only when it differs from the canonical spelling; a column without one is written in the canonical spelling and is named after it, which is the text the database reads. An aliased column is named by its alias and keeps no layout.
$query = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('SELECT 1 AS one, 1+1');
[$query->statement->columns[0]->alias?->value, $query->statement->columns[1]->layout?->text(), $query->toString()] // => ['one', '1+1', 'SELECT 1 AS one, 1+1']Properties§
public Scalar $expressionpublic Name|null $alias = nullpublic Layout|null $layout = nullpublic bool $as = trueMethods§
public function __construct(
public Scalar $expression,
public Name|null $alias = null,
public Layout|null $layout = null,
public bool $as = true,
)Parameters
$expression | Scalar | The projected expression |
$alias | Name|null | The output name |
$layout | Layout|null | The spelling of the expression of a column without an alias when it is not the canonical one |
$as | bool | Whether the keyword AS introduces the alias; SQLite names a column after the text of an expression, which includes it |
Throws
InvalidConstruction When AS is left out without an alias, an aliased column has a layout, or the layout does not spell one token per rendered token, keeps whitespace alone after the expression, or is the canonical spellingCalls 6
- static-call Check::input() line 49
- method-call Canonical::layout() line 52
- new Canonical line 52
- function-call
countline 53 - method-call Canonical::trail() line 54
- method-call Canonical::same() line 55
public function render(Output $out): voidWrites the expression in its spelling and the alias.
Parameters
$out | Output |
Calls 4
- method-call Output::layout() line 64
- method-call Output::keyword() line 67
- method-call Output::name() line 69
- class-const NameUse::Alias() line 69
Test cases 192§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 11
ResultColumnTest::testRenderKeepsNoLayoutForTheCanonicalSpellingcallsResultColumnTest::testRenderKeepsTheCommentAfterTheExpressioncallsResultColumnTest::testRenderRefusesALayoutOfAnAliasedColumncallsResultColumnTest::testRenderRefusesALayoutThatChangesATokencallsResultColumnTest::testRenderRefusesALayoutThatDoesNotSpellTheExpressioncallsResultColumnTest::testRenderRefusesTheCanonicalSpellingAsALayoutcallsResultColumnTest::testRenderRefusesToLeaveOutAsWithoutAnAliascallsResultColumnTest::testRenderRefusesWhitespaceAloneAfterTheExpressioncallsResultColumnTest::testRenderWritesANewlyBuiltColumncallsResultColumnTest::testRenderWritesTheAliasWithAsWhenItWasWrittencallsResultColumnTest::testRenderWritesTheExpressionInItsLayoutcalls
Other tests reaching this symbol 181
CallRuleTest::testExpressionKeepsTheArgumentOrderingOfAnAggregatecallsCallRuleTest::testExpressionLowersTheArgumentsTheStarFormAndTheQuantifiercallsCallRuleTest::testFilterLowersThePredicateOfTheFilterClausecallsCallRuleTest::testFilterOverLowersAFilterOnlyAWindowOnlyAndBothcallsCallRuleTest::testNameKeepsTheFunctionNameAsWrittencallsCallRuleTest::testOverLowersAWindowSpecificationOrAWindowNamecallsExpressionRuleTest::testColumnLowersTableAndSchemaQualifiedColumnUsescallsExpressionRuleTest::testConditionalLowersTheBaseTheBranchesAndTheElsePartcallsExpressionRuleTest::testExpressionKeepsEveryParenthesisPairAsAGroupingcallsExpressionRuleTest::testExpressionLowersAScalarSubqueryAndAnExistsTestcallsExpressionRuleTest::testExpressionLowersCollateCastAndRowExpressionscallsExpressionRuleTest::testExpressionLowersRaiseWithAndWithoutAMessagecallsExpressionRuleTest::testListLowersAnEmptyAndAFilledExpressionListcallsExpressionRuleTest::testOptionalListIsNullWithoutParenthesesAfterATableValuedIncallsExpressionRuleTest::testParameterLowersEveryPrefixWithItsLabelcallsExpressionRuleTest::testTermLowersALiteralTermcallsExpressionRuleTest::testWordLowersAnUnqualifiedWordByHowItIsWrittencallsOperatorRuleTest::testExpressionKeepsTheOperandsInWrittenOrderAndTheStructureTheParserChosecallsOperatorRuleTest::testExpressionLowersEveryBinaryOperatorByItsSpellingcallsOperatorRuleTest::testExpressionLowersTheIsFamilycallsOperatorRuleTest::testExpressionLowersThePrefixOperatorscallsPredicateRuleTest::testExpressionLowersMembershipTestsAgainstAListAQueryAndATablecallsPredicateRuleTest::testExpressionLowersRangeTestscallsPredicateRuleTest::testExpressionLowersTheNullTestsByTheirSpellingcallsPredicateRuleTest::testMatchKeepsTheEscapeOperandcallsPredicateRuleTest::testMatchLowersEachPatternOperatorWithItsNegationcallsPredicateRuleTest::testNegatedTellsWhetherNotIsWrittenBeforeBetweenOrIncallsWindowRuleTest::testBoundLowersEveryBoundaryKindWithItsOffsetcallsWindowRuleTest::testExclusionLowersEachExclusionAndNullWithoutItcallsWindowRuleTest::testFrameLowersAStartOnlyFrameAndABetweenFrameOfEveryUnitcallsWindowRuleTest::testWindowLowersEachOfTheSixSpecificationFormscallsConflictRuleTest::testRaisedLowersTheAlgorithmsRaiseCanNamecallsLiteralRuleTest::testNumberDropsTheDigitSeparatorsOfARealTokencallsLiteralRuleTest::testNumberLowersAHexadecimalIntegerWithUpperCasedDigitscallsLiteralRuleTest::testNumberLowersEverySpellingOfARealNumbercallsLiteralRuleTest::testPlainLowersAFloatingPointTokenByItsPartscallsLiteralRuleTest::testTermLowersABlobWithUpperCasedDigitscallsLiteralRuleTest::testTermLowersAnIntegerAndDropsItsDigitSeparatorscallsLiteralRuleTest::testTermLowersNullAndADecodedStringcallsLiteralRuleTest::testTermLowersTheCurrentTimeKeywordscallsNameRuleTest::testCollationOfAnExpressionIsDecodedLikeAnyNamecallsNameRuleTest::testTokenDecodesAnIdentifierTokenAndKeepsItsCasecallsTypeNameRuleTest::testMinusNumberLowersAMinusSignedNumbercallsTypeNameRuleTest::testNamedIsNullWhenNoTypeIsWrittencallsTypeNameRuleTest::testNamedKeepsOneOrTwoNumericArgumentsWithTheirSignscallsTypeNameRuleTest::testPlusNumberLowersAnUnsignedAndAPlusSignedNumbercallsTypeNameRuleTest::testSignedLowersARealAndAHexadecimalArgumentcallsTypeNameRuleTest::testWordsKeepTheQuotingOfEachWordcallsMutationRuleTest::testReturningIsEmptyWithoutTheClausecallsMutationRuleTest::testWhereReturningLowersEachOfTheFourTailscallsUpsertRuleTest::testTailLowersAnEmptyTailAndAReturningOnlyTailcallsResultRuleTest::testAliasReadsTheAliasAfterAsABareWordAStringOrNonecallsResultRuleTest::testColumnKeepsTheLayoutOfAnUnaliasedExpressionThatIsNotCanonicalcallsResultRuleTest::testColumnsLowersExpressionsStarsAndTableStarsInWrittenOrdercallsResultRuleTest::testKeywordTellsWhetherAsIntroducesTheAliascallsResultRuleTest::testMarkerCarriesNothingIntoTheResultColumnscallsSortRuleTest::testTermsTreatsAnIntegerAsAResultColumnPositionOnlyInTheOrderByOfAQuerycallsDerivationTest::testInspectedDiscardsDeclarationsAndRowsButKeepsFactsAndDiagnosticscallsFactsTest::testCoversTellsNodesOfTheOperationFromOtherscallsOperationTest::testToStringIsNotReachedForANodeUsedAtTwoPositionscallsOperationTest::testToStringOfANewRootBuiltFromExplicitStructurecallsQueryTest::testDeriveQueryRecordsTheOutputOfANestedQueryAtItsPositioncallsEquivalenceTest::testDifferenceNamesAChangedClasscallsEquivalenceTest::testDifferenceNamesAChangedEnumCaseAndADroppedAliascallsEquivalenceTest::testDifferenceNamesAChangedScalarValuecallsEquivalenceTest::testDifferenceNamesAListOfAnotherLengthcallsLeafEmbeddingTest::testDroppedAnswersTheFirstLeafTheStructureLostcallsLeafEmbeddingTest::testDroppedComparesByIdentityAndNotByValuecallsLeafEmbeddingTest::testDroppedIsNullWhenEveryLeafIsReachablecallsPublicationTest::testEstablishDerivesTheFactsAndRendersCorrespondingSqlcallsPublicationTest::testEstablishRefusesANodeUsedAtTwoPositionscallsValueGraphTest::testObjectsListsEveryReachableObjectOncecallsValueGraphTest::testObjectsRefusesAClassOutsideTheAdmittedNamespacescallsValueGraphTest::testObjectsRefusesAnAnonymousClassWhateverInterfaceItImplementscallsCanonicalTest::testLayoutKeepsTheLayoutsNestedInTheNodecallsClosedListTest::testOfAcceptsAListThatReachesTheMinimumcallsExpressionAffinityTest::testReferenceReadsADoubleQuotedWordThatIsNoColumnAsAStringWithoutAffinitycallsValueKindsTest::testResultsUnitesTheKindsOfEveryResultOfACasecallsPrecedenceTest::testEdgesOfAPostfixOperatorHaveNoRightOperandcallsInsertFactsTest::testDeriveBindsTheWithClauseAndReturnsTheTargetRowcallsMutationScopeTest::testReturningIsNullWithoutColumnsAndProjectsTheTargetOtherwisecallsTriggerFactsTest::testDeriveHidesTheRowThatTheEventDoesNotProvidecallsTriggerFactsTest::testDeriveMakesTheRowsOfTheEventVisibleByQualifierOnlycallsResultNamesTest::testRelationPrefersTheAliasThenTheWrittenWordThenTheTextcallsResultNamesTest::testResolvedLeavesAWordConditionalOnAMissingDeclarationUnnamedcallsResultNamesTest::testSpanAnswersTheLayoutTextOrTheCanonicalRenderingcallsResultNamesTest::testUnnamedAnswersTheInputsAnUndecidedNameDependsOncallsBindParameterTest::testDeriveScalarDependsOnTheBoundValuecallsBindParameterTest::testMarkerReadsEveryWrittenPrefixcallsBindParameterTest::testRenderWritesANewlyBuiltParametercallsCaseBranchTest::testRenderKeepsTheConditionAndTheResultInOrdercallsCaseBranchTest::testRenderWritesANewlyBuiltBranchcallsCaseExpressionTest::testDeriveScalarChoosesAmongTheResultTypesAndIsNotNullWithElsecallsCastTest::testDeriveScalarReadsTheTypeNameAndItsArgumentscallsCollateTest::testAcceptsAPrefixOperandWhichBindsTightercallsCollateTest::testDeriveScalarCollatesAPrefixExpressioncallsCollateTest::testDeriveScalarKeepsTheTypeAndNullFactAndLeavesTheResolutionToTheOperandcallsCollateTest::testDeriveScalarReportsACollatedRowValuecallsCollateTest::testRenderWritesANewlyBuiltCollationcallsColumnUseTest::testDeriveScalarDependsOnAnUndeclaredRelationcallsColumnUseTest::testDeriveScalarReportsAMissingColumncallsColumnUseTest::testDeriveScalarResolvesADeclaredColumnWithItsFactscallsColumnUseTest::testRenderQuotesANameThatNeedsItcallsDoubleQuotedWordTest::testDeriveScalarDependsOnAnUndeclaredRelationcallsDoubleQuotedWordTest::testDeriveScalarReadsTheWordAsTextWhenNoColumnCanResolvecallsDoubleQuotedWordTest::testDeriveScalarResolvesADeclaredColumncallsDoubleQuotedWordTest::testRenderDoublesAnEmbeddedDoubleQuotecallsFunctionCallTest::testDeriveScalarAcceptsAggregatesUsedAsWindowsAndNamedWindowscallsFunctionCallTest::testDeriveScalarReadsThePartsOfAnAggregateCallcallsFunctionCallTest::testDeriveScalarReportsAWrongArgumentCountcallsFunctionCallTest::testRenderWritesANewlyBuiltCallcallsGroupedTest::testDeriveScalarKeepsANullOperandNullcallsGroupedTest::testDeriveScalarKeepsTheTypeAndNullFactAndLeavesTheResolutionToTheOperandcallsBlobLiteralTest::testDeriveScalarGivesBlobcallsBlobLiteralTest::testRenderWritesANewlyBuiltBlobcallsCurrentTimeTest::testDeriveScalarGivesTextThatIsNeverNullcallsCurrentTimeTest::testRenderWritesANewlyBuiltKeywordcallsHexLiteralTest::testDeriveScalarGivesIntegercallsHexLiteralTest::testDeriveScalarReportsALiteralWiderThanSixtyFourBitscallsHexLiteralTest::testRenderWritesANewlyBuiltLiteralcallsIntegerLiteralTest::testDeriveScalarGivesIntegerWhenTheValueFitscallsIntegerLiteralTest::testDeriveScalarGivesRealForALargerValuecallsIntegerLiteralTest::testRenderWritesANewlyBuiltLiteralcallsNullLiteralTest::testDeriveScalarGivesTheNullOnlyTypecallsNullLiteralTest::testRenderWritesANewlyBuiltLiteralcallsRealLiteralTest::testDeriveScalarGivesRealcallsRealLiteralTest::testRenderWritesANewlyBuiltLiteralcallsTextLiteralTest::testDeriveScalarGivesTextAndKeepsTheDecodedValuecallsTextLiteralTest::testRenderWritesANewlyBuiltLiteralcallsTimeKeywordTest::testFromMatchesTheKeywordOfAnAnalyzedExpressioncallsBetweenTest::testRenderWritesANewlyBuiltTestcallsBinaryTest::testRenderWritesANewlyBuiltOperationcallsNullTestTest::testRenderWritesANewlyBuiltTestcallsPatternMatchTest::testRenderWritesANewlyBuiltMatchcallsUnaryTest::testRenderWritesANewlyBuiltNegationOverASumcallsParameterPrefixTest::testFromMatchesThePrefixOfAnAnalyzedParametercallsRaiseActionTest::testFromMatchesTheActionOfAnAnalyzedRaisecallsRaiseTest::testDeriveScalarYieldsNoValueInsideATriggercallsRaiseTest::testRenderWritesANewlyBuiltRaisecallsRowExpressionTest::testDeriveScalarCombinesTheNullFactsOfTheElementscallsRowExpressionTest::testDeriveScalarGivesARowOfTheWrittenWidthcallsExistsTest::testRenderWritesANewlyBuiltTestcallsInListTest::testRenderWritesANewlyBuiltTestcallsInQueryTest::testRefusesAnOperandThatEndsInAWeakerOperatorcallsInQueryTest::testRenderWritesANewlyBuiltTestcallsInTableTest::testRenderWritesANewlyBuiltTestcallsScalarSubqueryTest::testDeriveScalarDerivesTheQueryInsideTheEnvironmentOfTheExpressioncallsScalarSubqueryTest::testRenderWritesANewlyBuiltSubquerycallsTruthWordTest::testDeriveScalarDependsOnAnUndeclaredRelationcallsTruthWordTest::testDeriveScalarReadsTheConstantWhenNoColumnCanResolvecallsTruthWordTest::testDeriveScalarResolvesAColumnNamedTrueOrFalsecallsTruthWordTest::testRenderWritesANewlyBuiltWordcallsFrameBoundKindTest::testCasesMatchTheBoundariesOfAnAnalyzedFramecallsFrameBoundTest::testReadsTheOffsetOfAnAnalyzedBoundarycallsFrameBoundTest::testRenderWritesANewlyBuiltBoundarycallsFrameExclusionTest::testFromMatchesTheExclusionOfAnAnalyzedFramecallsFrameTest::testReadsBothEndsAndTheExclusioncallsFrameTest::testRenderWritesANewlyBuiltFramecallsFrameUnitTest::testFromMatchesTheUnitOfAnAnalyzedFramecallsWindowDefinitionTest::testRenderWritesANewlyBuiltDefinitioncallsWindowSpecTest::testExpressionsListsPartitionOrderingAndOffsetsInWrittenOrdercallsWindowSpecTest::testReadsEveryPartOfAnAnalyzedWindowcallsWindowSpecTest::testRenderWritesANewlyBuiltSpecificationcallsInsertSelectTest::testRejectsANonLastUpsertWithoutAConflictTargetcallsCompoundTest::testRenderRefusesAnIntegerConstantAsAnOrdinaryOrderByTermcallsCompoundTest::testRenderRefusesAnOrderingAfterAValuesArmcallsCompoundTest::testRenderRefusesASingleArmcallsCompoundTest::testRenderWritesANewlyBuiltCompoundcallsLimitTest::testRenderWritesACountAlonecallsListedColumnTest::testRenderWritesANewlyBuiltNamecallsSortTermTest::testRenderWritesANewlyBuiltTermcallsSelectTest::testRenderWritesANewlyBuiltSelectioncallsCommonTableTest::testRenderWritesANewlyBuiltTablecallsWithQueryTest::testDeriveQueryTypesARecursiveColumnAsAnyStorageClassInTheRecursiveArmcallsWithQueryTest::testRenderWritesANewlyBuiltQuerycallsDerivedQueryTest::testRenderWritesTheQueryInParenthesesWithItsAliascallsCreateTriggerTest::testRejectsAStepWithAWithClausecallsCreateTriggerTest::testRejectsColumnsOnAnEventOtherThanUpdatecallsCreateTriggerTest::testRenderWritesEveryPartInGrammarOrdercallsTriggerTableTest::testRenderWritesTheSchemaAndTheNamecallsSignedNumberTest::testRenderWritesANewlyBuiltNumbercalls
Relations§
Instantiated in 1
Constant reads 6
- class-const SqlSemantics\Platform\Sqlite\Statement\Mutation\Delete::__construct() packages/sql-semantics-sqlite/src/Statement/Mutation/Delete.php:53
- class-const SqlSemantics\Platform\Sqlite\Statement\Mutation\InsertDefaults::__construct() packages/sql-semantics-sqlite/src/Statement/Mutation/InsertDefaults.php:49
- class-const SqlSemantics\Platform\Sqlite\Statement\Mutation\InsertRows::__construct() packages/sql-semantics-sqlite/src/Statement/Mutation/InsertRows.php:62
- class-const SqlSemantics\Platform\Sqlite\Statement\Mutation\InsertSelect::__construct() packages/sql-semantics-sqlite/src/Statement/Mutation/InsertSelect.php:68
- class-const SqlSemantics\Platform\Sqlite\Statement\Mutation\Update::__construct() packages/sql-semantics-sqlite/src/Statement/Mutation/Update.php:77
- class-const SqlSemantics\Platform\Sqlite\Statement\Query\Select::__construct() packages/sql-semantics-sqlite/src/Statement/Query/Select.php:89
Type checks 3
- instanceof SqlSemantics\Platform\Sqlite\Rules\Query\Projection::items() packages/sql-semantics-sqlite/src/Rules/Query/Projection.php:58
- instanceof SqlSemantics\Platform\Sqlite\Rules\Query\ResultNames::column() packages/sql-semantics-sqlite/src/Rules/Query/ResultNames.php:222
- instanceof SqlSemantics\Platform\Sqlite\Rules\Query\SelectFacts::aliases() packages/sql-semantics-sqlite/src/Rules/Query/SelectFacts.php:84
Type declarations 8
- type SqlSemantics\Platform\Sqlite\Lowering\Query\ResultRule packages/sql-semantics-sqlite/src/Lowering/Query/ResultRule.php:83
- type SqlSemantics\Platform\Sqlite\Rules\Query\ResultNames packages/sql-semantics-sqlite/src/Rules/Query/ResultNames.php:71
- type SqlSemantics\Platform\Sqlite\Rules\Query\ResultNames packages/sql-semantics-sqlite/src/Rules/Query/ResultNames.php:81
- type SqlSemantics\Platform\Sqlite\Rules\Query\ResultNames packages/sql-semantics-sqlite/src/Rules/Query/ResultNames.php:107
- type SqlSemantics\Platform\Sqlite\Rules\Query\ResultNames packages/sql-semantics-sqlite/src/Rules/Query/ResultNames.php:131
- type SqlSemantics\Platform\Sqlite\Rules\Query\ResultNames packages/sql-semantics-sqlite/src/Rules/Query/ResultNames.php:164
- type SqlSemantics\Platform\Sqlite\Rules\Query\ResultNames packages/sql-semantics-sqlite/src/Rules/Query/ResultNames.php:174
- type SqlSemantics\Platform\Sqlite\Rules\Query\ResultNames packages/sql-semantics-sqlite/src/Rules/Query/ResultNames.php:219