88 * PDO uses camel case naming, enable non-snake case:
99 * phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
1010 * phpcs:disable WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
11+ * phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
1112 *
1213 * PDO uses $class as a variable name, enable it:
1314 * phpcs:disable Universal.NamingConventions.NoReservedKeywordParameterNames.classFound
@@ -118,7 +119,7 @@ public function fetchAll( $mode = PDO::FETCH_DEFAULT, ...$args ): array {
118119 * - PDO::FETCH_BOUND: bind values to PHP variables, can't be used with fetchAll()
119120 * - PDO::FETCH_FUNC: custom function, only works with fetchAll(), can't be default [1 extra arg]
120121 */
121- class WP_MySQL_On_SQLite_Statement extends PDOStatement {
122+ class WP_MySQL_On_SQLite_Statement extends PDOStatement implements IteratorAggregate {
122123 use WP_MySQL_On_SQLite_Statement_PHP_Compat;
123124
124125 /**
@@ -139,13 +140,20 @@ class WP_MySQL_On_SQLite_Statement extends PDOStatement {
139140 * Constructor.
140141 *
141142 * @param PDOStatement $statement The original PDO statement.
142- * @param int $affected_rows The number of affected rows.
143+ * @param string $query The original MySQL query.
144+ * @param int|null $affected_rows The number of affected rows.
143145 */
144146 public function __construct (
145147 PDOStatement $ statement ,
148+ string $ query ,
146149 ?int $ affected_rows = null
147150 ) {
148- $ this ->statement = $ statement ;
151+ $ this ->statement = $ statement ;
152+
153+ // Userland can only initialize PDOStatement::$queryString on PHP 8.1+.
154+ if ( PHP_VERSION_ID >= 80100 ) {
155+ $ this ->queryString = $ query ;
156+ }
149157 $ this ->affected_rows = $ affected_rows ;
150158 }
151159
@@ -239,7 +247,7 @@ public function getColumnMeta( $column ): array {
239247 * or null if there is no error.
240248 */
241249 public function errorCode (): ?string {
242- throw new RuntimeException ( ' Not implemented ' );
250+ return $ this -> statement -> errorCode ( );
243251 }
244252
245253 /**
@@ -251,7 +259,11 @@ public function errorCode(): ?string {
251259 * 2: Driver-specific error message.
252260 */
253261 public function errorInfo (): array {
254- throw new RuntimeException ( 'Not implemented ' );
262+ // Normalize successful results. PDO_SQLite may retain stale driver-specific fields on PHP < 8.0.
263+ if ( '00000 ' === $ this ->statement ->errorCode () ) {
264+ return array ( '00000 ' , null , null );
265+ }
266+ return $ this ->statement ->errorInfo ();
255267 }
256268
257269 /**
@@ -282,7 +294,7 @@ public function setAttribute( $attribute, $value ): bool {
282294 * @return Iterator The iterator for the result set.
283295 */
284296 public function getIterator (): Iterator {
285- throw new RuntimeException ( ' Not implemented ' ) ;
297+ yield from $ this -> statement ;
286298 }
287299
288300 /**
@@ -300,7 +312,7 @@ public function nextRowset(): bool {
300312 * @return bool True on success, false on failure.
301313 */
302314 public function closeCursor (): bool {
303- throw new RuntimeException ( ' Not implemented ' );
315+ return $ this -> statement -> closeCursor ( );
304316 }
305317
306318 /**
@@ -313,8 +325,8 @@ public function closeCursor(): bool {
313325 * @param mixed $driverOptions Optional parameters for the driver.
314326 * @return bool True on success, false on failure.
315327 */
316- public function bindColumn ( $ column , &$ var , $ type = null , $ maxLength = null , $ driverOptions = null ): bool {
317- throw new RuntimeException ( ' Not implemented ' );
328+ public function bindColumn ( $ column , &$ var , $ type = PDO :: PARAM_STR , $ maxLength = 0 , $ driverOptions = null ): bool {
329+ return $ this -> statement -> bindColumn ( $ column , $ var , $ type , $ maxLength , $ driverOptions );
318330 }
319331
320332 /**
0 commit comments