Skip to content

Commit edee595

Browse files
committed
Add TODO for UNSIGNED cast emulation
MySQL wraps negative values on UNSIGNED casts using modular arithmetic (2^64), but SQLite has no unsigned integer type. Mark this as a known limitation to be addressed.
1 parent 79c53fa commit edee595

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

packages/mysql-on-sqlite/src/sqlite/class-wp-pdo-mysql-on-sqlite.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3790,6 +3790,8 @@ private function translate( $node ): ?string {
37903790
return 'TEXT';
37913791
case WP_MySQL_Lexer::SIGNED_SYMBOL:
37923792
case WP_MySQL_Lexer::UNSIGNED_SYMBOL:
3793+
// @TODO: Emulate UNSIGNED semantics. MySQL wraps negative
3794+
// values, but SQLite has no unsigned integer type.
37933795
return 'INTEGER';
37943796
case WP_MySQL_Lexer::DECIMAL_SYMBOL:
37953797
case WP_MySQL_Lexer::FLOAT_SYMBOL:
@@ -4234,6 +4236,7 @@ private function translate_simple_expr_body( WP_Parser_Node $node ): string {
42344236

42354237
if ( null !== $cast_type ) {
42364238
// CONVERT(expr, type): Translate to cast expression.
4239+
// TODO: Emulate UNSIGNED cast. SQLite has no unsigned integer type.
42374240
return sprintf( 'CAST(%s AS %s)', $expr, $this->translate( $cast_type ) );
42384241
} else {
42394242
// CONVERT(expr USING charset): Keep "expr" as is (no SQLite support).

packages/mysql-on-sqlite/tests/WP_SQLite_Driver_Tests.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9971,7 +9971,8 @@ public function testCastExpression(): void {
99719971
'expr_5' => 'abc',
99729972
'expr_6' => 'abc', // 'ab' In MySQL
99739973
'expr_7' => '-10',
9974-
'expr_8' => '-10', // 18446744073709551606 in MySQL
9974+
// @TODO: Emulate UNSIGNED cast. MySQL returns 18446744073709551606 (2^64 - 10).
9975+
'expr_8' => '-10',
99759976
'expr_9' => '2025-10-05 14:05:28', // 2025-10-05 in MySQL
99769977
'expr_10' => '2025-10-05 14:05:28', // 14:05:28 in MySQL
99779978
'expr_11' => '2025-10-05 14:05:28',
@@ -10005,6 +10006,7 @@ public function testConvertExpression(): void {
1000510006
'expr_1' => 'abc',
1000610007
'expr_2' => 'abc',
1000710008
'expr_3' => '-10',
10009+
// @TODO: Emulate UNSIGNED cast. MySQL returns 18446744073709551606 (2^64 - 10).
1000810010
'expr_4' => '-10',
1000910011
'expr_5' => '123.456',
1001010012
'expr_6' => '2025-10-05',

0 commit comments

Comments
 (0)