classCast
final class Cast
implements Scalar
uses Snapshot
Public API: explicitly declared with
@visibility public.A conversion of a value to the storage class the affinity of a type name selects.
Rule: SQLITE-CAST-001. The affinity of the type name decides the result: INTEGER, TEXT, BLOB and REAL affinity give that storage class; NUMERIC affinity, which an absent type name also has, gives INTEGER or REAL. A NULL operand stays NULL, so the NULL fact is that of the operand. Source: https://sqlite.org/lang_expr.html#castexpr. Status: Implemented.
$query = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('SELECT CAST(a AS VARCHAR(10)) FROM t');
[$query->statement->columns[0]->expression->target->text(), $query->field(0)->type->descriptor] // => ['VARCHAR', \SqlSemantics\Platform\Sqlite\Statement\Type\Storage::Text]Properties§
public Scalar $operandpublic TypeName|null $target = nullMethods§
public function __construct(public Scalar $operand, public TypeName|null $target = null)Parameters
$operand | Scalar | The converted expression |
$target | TypeName|null | The type name; null when none is written |
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives the storage class from the affinity of the type name.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 13
- method-call Derivation::scalar() line 50
- new ScalarFact line 55
- class-const Affinity::Numeric() line 57
- class-const Affinity::Integer() line 58
- class-const Storage::Integer() line 58
- class-const Affinity::Text() line 59
- class-const Storage::Text() line 59
- class-const Affinity::Blob() line 60
- class-const Storage::Blob() line 60
- class-const Affinity::Real() line 61
- class-const Storage::Real() line 61
- method-call Storages::fact() line 65
- new Storages line 65
public function render(Output $out): voidTest cases 16§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 1
Other tests reaching this symbol 15
ExpressionRuleTest::testExpressionLowersCollateCastAndRowExpressionscallsTypeNameRuleTest::testMinusNumberLowersAMinusSignedNumbercallsTypeNameRuleTest::testNamedIsNullWhenNoTypeIsWrittencallsTypeNameRuleTest::testNamedKeepsOneOrTwoNumericArgumentsWithTheirSignscallsTypeNameRuleTest::testPlusNumberLowersAnUnsignedAndAPlusSignedNumbercallsTypeNameRuleTest::testSignedLowersARealAndAHexadecimalArgumentcallsTypeNameRuleTest::testWordsKeepTheQuotingOfEachWordcallsExpressionAffinityTest::testAdjustedAppliesTheRulesOfACompoundColumncallsExpressionAffinityTest::testOfLooksThroughParenthesesAndCollateAndReadsCastsRowValuesAndSubqueriescallsExpressionAffinityTest::testWrittenReadsTheExpressionOfAPositionAndNothingForAStarcallsNumberSignTest::testEachSignIsReadFromItsSpellingcallsSignedNumberTest::testRenderWritesANewlyBuiltNumbercallsSignedNumberTest::testRenderWritesEveryKindOfNumericLiteralcallsSignedNumberTest::testRenderWritesTheSignDirectlyBeforeTheNumbercallsTypeNameTest::testRenderWritesTheWordsAndTheArgumentsWithoutSpacescalls
Relations§
Instantiated in 1
Type checks 4
- instanceof SqlSemantics\Platform\Sqlite\Rules\Definition\Expression\LiteralDefaults::constant() packages/sql-semantics-sqlite/src/Rules/Definition/Expression/LiteralDefaults.php:88
- instanceof SqlSemantics\Platform\Sqlite\Rules\Definition\Query\ExpressionAffinity::of() packages/sql-semantics-sqlite/src/Rules/Definition/Query/ExpressionAffinity.php:82
- instanceof SqlSemantics\Platform\Sqlite\Rules\Definition\Query\ExpressionAffinity::adjusted() packages/sql-semantics-sqlite/src/Rules/Definition/Query/ExpressionAffinity.php:303
- instanceof SqlSemantics\Platform\Sqlite\Rules\Definition\Query\ValueKinds::of() packages/sql-semantics-sqlite/src/Rules/Definition/Query/ValueKinds.php:104