Skip to content

Commit f752985

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 76a1113 commit f752985

8 files changed

Lines changed: 467 additions & 332 deletions

File tree

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

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,20 @@ class WP_MySQL_On_SQLite_Statement extends PDOStatement {
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,18 +153,21 @@ class WP_MySQL_On_SQLite_Statement extends PDOStatement {
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
) {
151-
$this->statement = $statement;
152-
$this->affected_rows = $affected_rows;
153-
$this->queryString = $query;
167+
$this->statement = $statement;
168+
$this->queryString = $query;
169+
$this->column_meta_resolver = $column_meta_resolver;
170+
$this->affected_rows = $affected_rows;
154171
}
155172

156173
/**
@@ -232,8 +249,15 @@ public function fetchObject( $class = 'stdClass', $constructorArgs = array() ) {
232249
* @return array|false The column metadata as an associative array,
233250
* or false if the column does not exist.
234251
*/
235-
public function getColumnMeta( $column ): array {
236-
throw new RuntimeException( 'Not implemented' );
252+
#[ReturnTypeWillChange]
253+
public function getColumnMeta( $column ) {
254+
if ( ! array_key_exists( $column, $this->resolved_column_meta ) ) {
255+
$this->resolved_column_meta[ $column ] = call_user_func(
256+
$this->column_meta_resolver,
257+
$column
258+
);
259+
}
260+
return $this->resolved_column_meta[ $column ];
237261
}
238262

239263
/**

0 commit comments

Comments
 (0)