Skip to content
This repository was archived by the owner on Sep 11, 2026. It is now read-only.

Commit acfde6a

Browse files
batonacclaude
andcommitted
Fix remaining CI failures across PHP and SQLite versions
- The fake D1 transport probes PDO::ATTR_STRINGIFY_FETCHES readability with a try/catch instead of a version check; reading the attribute throws IM001 on PHP 8.1. - On PHP < 7.3, where getColumnMeta() fails for empty result sets (PHP bug #79664), the fake now degrades to placeholder column names instead of none, keeping the column count accurate so that zero-row SELECTs are still recognized as result sets. - The no-UDF WEEK(x, 1) rewrite computes the ISO week from the day-of-year of the week's Thursday instead of STRFTIME('%V'), which requires SQLite 3.46+ and returned NULL on older libraries (CI links the system libsqlite 3.45.1). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 5300033 commit acfde6a

2 files changed

Lines changed: 23 additions & 17 deletions

File tree

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4826,16 +4826,24 @@ private function translate_function_call_without_udfs( string $name, array $args
48264826
* Mode 0 (weeks starting on Sunday) maps to the SQLite "%U"
48274827
* week number. Mode 1 (weeks starting on Monday, week 1 is
48284828
* the first week with 4+ days in the year) matches the ISO
4829-
* "%V" week number, except that early-January days belonging
4830-
* to the last week of the previous year yield the previous
4831-
* year's week number rather than MySQL's 0.
4829+
* week number, except in the week spanning the year
4830+
* boundary, where MySQL yields 0 (early January) or 53
4831+
* (late December) instead of the other year's ISO week
4832+
* number. The legacy PHP emulation had the same divergence.
4833+
*
4834+
* The ISO week is computed from the day-of-year of the
4835+
* Thursday in the date's week ("STRFTIME('%V')" would need
4836+
* SQLite 3.46+).
48324837
*/
48334838
$mode = $args[1] ?? '0';
48344839
if ( '0' === $mode ) {
48354840
return sprintf( "CAST(STRFTIME('%%U', %s) AS INTEGER)", $args[0] );
48364841
}
48374842
if ( '1' === $mode ) {
4838-
return sprintf( "CAST(STRFTIME('%%V', %s) AS INTEGER)", $args[0] );
4843+
return sprintf(
4844+
"((CAST(STRFTIME('%%j', DATE(%s, '-3 days', 'weekday 4')) AS INTEGER) - 1) / 7 + 1)",
4845+
$args[0]
4846+
);
48394847
}
48404848
throw $this->new_not_supported_exception(
48414849
'WEEK() with a mode other than 0 or 1 (the connection does not support user-defined functions)'

‎packages/mysql-on-sqlite/tests/tools/class-wp-sqlite-d1-fake-transport.php‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ public function __construct( ?PDO $pdo = null ) {
5353
$this->pdo->query( 'PRAGMA foreign_keys = ON' );
5454

5555
// Capture the handle's stringification setting, to restore it after
56-
// internal fetches. Reading the attribute requires PHP 8.1+; older
57-
// versions assume the tests' backend factory setting (true) for
58-
// injected handles.
59-
if ( PHP_VERSION_ID >= 80100 ) {
56+
// internal fetches. Reading the attribute is not supported on all
57+
// PHP versions; those assume the tests' backend factory setting
58+
// (true) for injected handles.
59+
try {
6060
$this->external_stringify = (bool) $this->pdo->getAttribute( PDO::ATTR_STRINGIFY_FETCHES );
61-
} else {
61+
} catch ( PDOException $e ) {
6262
$this->external_stringify = null !== $pdo;
6363
}
6464
}
@@ -195,11 +195,13 @@ private function run( string $sql, array $params ): array {
195195
$is_read = 1 === preg_match( '/^\s*(SELECT|PRAGMA|EXPLAIN|WITH)\b/i', $sql );
196196

197197
/*
198-
* Collect the column names. On some PHP builds, PDO SQLite fails
198+
* Collect the column names. On PHP < 7.3, PDO SQLite fails
199199
* "getColumnMeta()" for statements with an empty result set (see
200200
* the PHP bug #79664 workarounds in the driver). In that case, the
201-
* fake degrades to reporting no column names for empty results —
202-
* unlike a real D1 proxy, which reports them accurately.
201+
* fake degrades to placeholder column names: the result has no
202+
* rows, so the names never surface in data, while the column
203+
* count remains accurate — unlike a real D1 proxy, which reports
204+
* the names accurately.
203205
*/
204206
$columns = array();
205207
for ( $i = 0; $i < $stmt->columnCount(); $i++ ) {
@@ -208,11 +210,7 @@ private function run( string $sql, array $params ): array {
208210
} catch ( PDOException $e ) {
209211
$meta = false;
210212
}
211-
if ( false === $meta ) {
212-
$columns = array();
213-
break;
214-
}
215-
$columns[] = $meta['name'];
213+
$columns[] = false === $meta ? "column$i" : $meta['name'];
216214
}
217215

218216
$rows = array();

0 commit comments

Comments
 (0)