@@ -727,9 +727,17 @@ function ( string $sql, array $params ) {
727727 #[ReturnTypeWillChange]
728728 public function query ( string $ query , ?int $ fetch_mode = PDO ::FETCH_COLUMN , ...$ fetch_mode_args ) {
729729 $ this ->flush ();
730- $ this ->pdo_fetch_mode = $ fetch_mode ;
731730 $ this ->last_mysql_query = $ query ;
732731
732+ /**
733+ * Use "PDO::FETCH_NUM" fetch mode, as the "WP_PDO_Synthetic_Statement"
734+ * expects the row data to be passed as an array of values.
735+ *
736+ * @TODO: We can remove this when we use the SQLite PDOStatements directly,
737+ * likely via a proxy, and will stop fetching the results eagerly.
738+ */
739+ $ this ->pdo_fetch_mode = PDO ::FETCH_NUM ;
740+
733741 try {
734742 // Parse the MySQL query.
735743 $ parser = $ this ->create_parser ( $ query );
@@ -772,8 +780,10 @@ public function query( string $query, ?int $fetch_mode = PDO::FETCH_COLUMN, ...$
772780 $ this ->commit_wrapper_transaction ();
773781 }
774782
783+ $ columns = is_array ( $ this ->last_column_meta ) ? $ this ->last_column_meta : array ();
784+ $ rows = is_array ( $ this ->last_result ) ? $ this ->last_result : array ();
775785 $ affected_rows = is_int ( $ this ->last_return_value ) ? $ this ->last_return_value : 0 ;
776- return new WP_PDO_Synthetic_Statement ( $ affected_rows );
786+ return new WP_PDO_Synthetic_Statement ( $ columns , $ rows , $ affected_rows );
777787 } catch ( Throwable $ e ) {
778788 try {
779789 $ this ->rollback_user_transaction ();
@@ -2444,7 +2454,7 @@ private function execute_show_statement( WP_Parser_Node $node ): void {
24442454 } else {
24452455 $ this ->set_results_from_fetched_data (
24462456 array (
2447- ( object ) array (
2457+ array (
24482458 'Table ' => $ table_name ,
24492459 'Create Table ' => $ sql ,
24502460 ),
@@ -2483,7 +2493,7 @@ private function execute_show_statement( WP_Parser_Node $node ): void {
24832493 case WP_MySQL_Lexer::GRANTS_SYMBOL :
24842494 $ this ->set_results_from_fetched_data (
24852495 array (
2486- ( object ) array (
2496+ array (
24872497 'Grants for root@% ' => 'GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `root`@`localhost` WITH GRANT OPTION ' ,
24882498 ),
24892499 )
@@ -2572,7 +2582,7 @@ private function execute_show_collation_statement( WP_Parser_Node $node ): void
25722582 )
25732583 );
25742584 $ this ->store_last_column_meta_from_statement ( $ stmt );
2575- $ this ->set_results_from_fetched_data ( $ stmt ->fetchAll ( PDO :: FETCH_OBJ ) );
2585+ $ this ->set_results_from_fetched_data ( $ stmt ->fetchAll ( $ this -> pdo_fetch_mode ) );
25762586 }
25772587
25782588 /**
@@ -2604,7 +2614,7 @@ private function execute_show_databases_statement( WP_Parser_Node $node ): void
26042614 );
26052615
26062616 $ this ->store_last_column_meta_from_statement ( $ stmt );
2607- $ databases = $ stmt ->fetchAll ( PDO :: FETCH_OBJ );
2617+ $ databases = $ stmt ->fetchAll ( $ this -> pdo_fetch_mode );
26082618 $ this ->set_results_from_fetched_data ( $ databases );
26092619 }
26102620
@@ -2690,7 +2700,7 @@ private function execute_show_index_statement( WP_Parser_Node $node ): void {
26902700 );
26912701
26922702 $ this ->store_last_column_meta_from_statement ( $ stmt );
2693- $ index_info = $ stmt ->fetchAll ( PDO :: FETCH_OBJ );
2703+ $ index_info = $ stmt ->fetchAll ( $ this -> pdo_fetch_mode );
26942704 $ this ->set_results_from_fetched_data ( $ index_info );
26952705 }
26962706
@@ -2753,7 +2763,7 @@ private function execute_show_table_status_statement( WP_Parser_Node $node ): vo
27532763 );
27542764
27552765 $ this ->store_last_column_meta_from_statement ( $ stmt );
2756- $ table_info = $ stmt ->fetchAll ( PDO :: FETCH_OBJ );
2766+ $ table_info = $ stmt ->fetchAll ( $ this -> pdo_fetch_mode );
27572767 if ( false === $ table_info ) {
27582768 $ this ->set_results_from_fetched_data ( array () );
27592769 }
@@ -2805,7 +2815,7 @@ private function execute_show_tables_statement( WP_Parser_Node $node ): void {
28052815 );
28062816
28072817 $ this ->store_last_column_meta_from_statement ( $ stmt );
2808- $ table_info = $ stmt ->fetchAll ( PDO :: FETCH_OBJ );
2818+ $ table_info = $ stmt ->fetchAll ( $ this -> pdo_fetch_mode );
28092819 if ( false === $ table_info ) {
28102820 $ this ->set_results_from_fetched_data ( array () );
28112821 }
@@ -2878,7 +2888,7 @@ private function execute_show_columns_statement( WP_Parser_Node $node ): void {
28782888 );
28792889
28802890 $ this ->store_last_column_meta_from_statement ( $ stmt );
2881- $ column_info = $ stmt ->fetchAll ( PDO :: FETCH_OBJ );
2891+ $ column_info = $ stmt ->fetchAll ( $ this -> pdo_fetch_mode );
28822892 if ( false === $ column_info ) {
28832893 $ this ->set_results_from_fetched_data ( array () );
28842894 }
@@ -2917,7 +2927,7 @@ private function execute_describe_statement( WP_Parser_Node $node ): void {
29172927 );
29182928
29192929 $ this ->store_last_column_meta_from_statement ( $ stmt );
2920- $ column_info = $ stmt ->fetchAll ( PDO :: FETCH_OBJ );
2930+ $ column_info = $ stmt ->fetchAll ( $ this -> pdo_fetch_mode );
29212931 $ this ->set_results_from_fetched_data ( $ column_info );
29222932 }
29232933
@@ -3239,14 +3249,14 @@ private function execute_administration_statement( WP_Parser_Node $node ): void
32393249
32403250 $ operation = strtolower ( $ first_token ->get_value () );
32413251 foreach ( $ errors as $ error ) {
3242- $ results [] = ( object ) array (
3252+ $ results [] = array (
32433253 'Table ' => $ this ->db_name . '. ' . $ table_name ,
32443254 'Op ' => $ operation ,
32453255 'Msg_type ' => 'Error ' ,
32463256 'Msg_text ' => $ error ,
32473257 );
32483258 }
3249- $ results [] = ( object ) array (
3259+ $ results [] = array (
32503260 'Table ' => $ this ->db_name . '. ' . $ table_name ,
32513261 'Op ' => $ operation ,
32523262 'Msg_type ' => 'status ' ,
0 commit comments