@@ -64,8 +64,14 @@ public function ensure_correct_information_schema(): void {
6464 throw new Exception ( 'The "wp_get_db_schema()" function was not defined. ' );
6565 }
6666 $ schema = wp_get_db_schema ();
67- foreach ( $ this ->driver ->parse_query ( $ schema ) as $ query ) {
68- $ create_node = $ query ->get_first_descendant_node ( 'createStatement ' );
67+ $ parser = $ this ->driver ->create_parser ( $ schema );
68+ while ( $ parser ->next_query () ) {
69+ $ ast = $ parser ->get_query_ast ();
70+ if ( null === $ ast ) {
71+ throw new WP_SQLite_Driver_Exception ( $ this ->driver , 'Failed to parse the MySQL query. ' );
72+ }
73+
74+ $ create_node = $ ast ->get_first_descendant_node ( 'createStatement ' );
6975 if ( $ create_node && $ create_node ->has_child_node ( 'createTable ' ) ) {
7076 $ name_node = $ create_node ->get_first_descendant_node ( 'tableName ' );
7177 $ name = $ this ->unquote_mysql_identifier (
@@ -86,7 +92,10 @@ public function ensure_correct_information_schema(): void {
8692 } else {
8793 // Other table (a WordPress plugin or unrelated to WordPress).
8894 $ sql = $ this ->generate_create_table_statement ( $ table );
89- $ ast = $ this ->driver ->parse_query ( $ sql )->current ();
95+ $ ast = $ this ->driver ->create_parser ( $ sql )->parse ();
96+ if ( null === $ ast ) {
97+ throw new WP_SQLite_Driver_Exception ( $ this ->driver , 'Failed to parse the MySQL query. ' );
98+ }
9099 }
91100 $ this ->information_schema_builder ->record_create_table ( $ ast );
92101 }
@@ -96,7 +105,10 @@ public function ensure_correct_information_schema(): void {
96105 foreach ( $ information_schema_tables as $ table ) {
97106 if ( ! in_array ( $ table , $ tables , true ) ) {
98107 $ sql = sprintf ( 'DROP %s ' , $ this ->quote_sqlite_identifier ( $ table ) );
99- $ ast = $ this ->driver ->parse_query ( $ sql )->current ();
108+ $ ast = $ this ->driver ->create_parser ( $ sql )->parse ();
109+ if ( null === $ ast ) {
110+ throw new WP_SQLite_Driver_Exception ( $ this ->driver , 'Failed to parse the MySQL query. ' );
111+ }
100112 $ this ->information_schema_builder ->record_drop_table ( $ ast );
101113 }
102114 }
0 commit comments