Skip to content

Commit 4f89be3

Browse files
committed
Snapshot result column metadata
Snapshot raw result metadata into each PDO statement, resolve and cache MySQL-compatible metadata lazily, and migrate consumers away from mutable driver-wide last-query metadata. Preserve the legacy metadata getters only on the deprecated WP_SQLite_Driver facade.
1 parent 1b0acc0 commit 4f89be3

8 files changed

Lines changed: 468 additions & 331 deletions

File tree

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

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,20 @@ class WP_MySQL_On_SQLite_Statement extends PDOStatement implements IteratorAggre
129129
*/
130130
private $statement;
131131

132+
/**
133+
* Resolve MySQL-compatible metadata by column index.
134+
*
135+
* @var callable
136+
*/
137+
private $column_meta_resolver;
138+
139+
/**
140+
* Resolved MySQL-compatible metadata, keyed by column index.
141+
*
142+
* @var array<int, array|false>
143+
*/
144+
private $resolved_column_meta = array();
145+
132146
/**
133147
* The number of affected rows.
134148
*
@@ -139,13 +153,15 @@ class WP_MySQL_On_SQLite_Statement extends PDOStatement implements IteratorAggre
139153
/**
140154
* Constructor.
141155
*
142-
* @param PDOStatement $statement The original PDO statement.
143-
* @param string $query The original MySQL query.
144-
* @param int|null $affected_rows The number of affected rows.
156+
* @param PDOStatement $statement The original PDO statement.
157+
* @param string $query The original MySQL query.
158+
* @param callable $column_meta_resolver Resolves metadata by column index.
159+
* @param int|null $affected_rows The number of affected rows.
145160
*/
146161
public function __construct(
147162
PDOStatement $statement,
148163
string $query,
164+
callable $column_meta_resolver,
149165
?int $affected_rows = null
150166
) {
151167
$this->statement = $statement;
@@ -154,7 +170,8 @@ public function __construct(
154170
if ( PHP_VERSION_ID >= 80100 ) {
155171
$this->queryString = $query;
156172
}
157-
$this->affected_rows = $affected_rows;
173+
$this->column_meta_resolver = $column_meta_resolver;
174+
$this->affected_rows = $affected_rows;
158175
}
159176

160177
/**
@@ -236,8 +253,15 @@ public function fetchObject( $class = 'stdClass', $constructorArgs = array() ) {
236253
* @return array|false The column metadata as an associative array,
237254
* or false if the column does not exist.
238255
*/
239-
public function getColumnMeta( $column ): array {
240-
throw new RuntimeException( 'Not implemented' );
256+
#[ReturnTypeWillChange]
257+
public function getColumnMeta( $column ) {
258+
if ( ! array_key_exists( $column, $this->resolved_column_meta ) ) {
259+
$this->resolved_column_meta[ $column ] = call_user_func(
260+
$this->column_meta_resolver,
261+
$column
262+
);
263+
}
264+
return $this->resolved_column_meta[ $column ];
241265
}
242266

243267
/**

0 commit comments

Comments
 (0)