classSignedLiteral
final class SignedLiteral
implements Scalar
uses Snapshot
@visibility public.A number literal written with a sign at a position that takes a signed literal, such as a column default.
In an expression a sign is the unary operator; at these positions the grammar reads the sign as part of the literal.
Rule: MYSQL-SIGNED-LITERAL-001. Facts: the type of the number, except that the negation of an integer beyond the signed 64-bit range, 9223372036854775808 and above, is DECIMAL: the server negates an unsigned integer literal through a decimal value (Item_uint::neg in sql/item.cc); never NULL. Diagnostics: none. Source: https://dev.mysql.com/doc/refman/8.4/en/number-literals.html, https://github.com/mysql/mysql-server/blob/8.4/sql/item.cc. Status: Implemented.
$literal = new \SqlSemantics\Platform\MySql\Statement\Literal\SignedLiteral(true, new \SqlSemantics\Platform\MySql\Statement\Literal\NumberLiteral('5'));
[$literal->negative, $literal->number->text] // => [true, '5']Properties§
public bool $negativepublic NumberLiteral $numberMethods§
public function __construct(public bool $negative, public NumberLiteral $number)Parameters
$negative | bool | Whether the sign is minus; otherwise plus |
$number | NumberLiteral | The unsigned number |
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives the number and applies the range rule of negation.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Test cases 4
SignedLiteralTest::testDeriveScalarAnswersDecimalForANegatedIntegerBeyondTheSignedRangecallsSignedLiteralTest::testDeriveScalarKeepsBigIntForTheLargestNegativeIntegerThatFitscallsSignedLiteralTest::testDeriveScalarKeepsTheTypeOfTheNumbercallsSignedLiteralTest::testDeriveScalarKeepsTheUnsignedTypeOfAPositiveIntegerBeyondTheSignedRangecalls
Calls 5
- method-call Derivation::scalar() line 51
- method-call NumberLiteral::beyondSigned() line 52
- new ScalarFact line 53
- new Known line 53
- new Decimal line 53
public function render(Output $out): voidWrites the sign and the number.
Parameters
$out | Output |
Test cases 1
Calls 1
- method-call Output::symbol() line 64
Test cases 7§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 6
SignedLiteralTest::testDeriveScalarAnswersDecimalForANegatedIntegerBeyondTheSignedRangecallsSignedLiteralTest::testDeriveScalarKeepsBigIntForTheLargestNegativeIntegerThatFitscallsSignedLiteralTest::testDeriveScalarKeepsTheTypeOfTheNumbercallsSignedLiteralTest::testDeriveScalarKeepsTheUnsignedTypeOfAPositiveIntegerBeyondTheSignedRangecallsSignedLiteralTest::testLoweredDefaultKeepsTheSignAndTheUnsignedTextcallsSignedLiteralTest::testRenderWritesTheSignAndTheNumbercalls