Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add a workaround for PHP PDO SQLite bug (#79664) in PHP < 7.3
  • Loading branch information
JanJakes committed Oct 1, 2025
commit f4beed61ee7d09b61260c25af0280d4f7479501e
25 changes: 25 additions & 0 deletions tests/WP_SQLite_Driver_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -8170,4 +8170,29 @@ public function testColumnInfoWithZeroRows(): void {
$column_info
);
}

public function testColumnInfoWithZeroRowsPhpBug(): void {
if ( PHP_VERSION_ID < 70300 ) {
$this->markTestSkipped( 'Skipping due to PHP bug (#79664)' );
}

$this->assertQuery( 'CREATE TABLE t ( id INT )' );
$this->assertQuery( 'SELECT * FROM t' );
$this->assertEquals( 1, $this->engine->get_last_column_count() );
$column_info = $this->engine->get_last_column_meta();
$this->assertCount( 1, $column_info );
$this->assertSame(
array(
'native_type' => 'LONG',
'pdo_type' => PDO::PARAM_INT,
'flags' => array(),
'table' => 't',
'name' => 'id',
'len' => 11,
'precision' => 0,
'sqlite:decl_type' => 'INTEGER',
),
$column_info[0]
);
}
}
21 changes: 21 additions & 0 deletions wp-includes/sqlite-ast/class-wp-sqlite-driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,27 @@ private function execute_select_statement( WP_Parser_Node $node ): void {
// seems to erase type information for expressions in the SELECT clause.
$this->last_column_meta = array();
for ( $i = 0; $i < $stmt->columnCount(); $i++ ) {
/*
* Workaround for PHP PDO SQLite bug (#79664) in PHP < 7.3.
* See also: https://github.com/php/php-src/pull/5654
*/
if ( PHP_VERSION_ID < 70300 ) {
try {
$this->last_column_meta[] = $stmt->getColumnMeta( $i );
} catch ( Throwable $e ) {
$this->last_column_meta[] = array(
'native_type' => 'null',
'pdo_type' => PDO::PARAM_NULL,
'flags' => array(),
'table' => '',
'name' => '',
'len' => -1,
'precision' => 0,
);
}
continue;
}

$this->last_column_meta[] = $stmt->getColumnMeta( $i );
}

Expand Down