@@ -64,8 +64,14 @@ public function ensure_correct_information_schema(): void {
64
64
throw new Exception ( 'The "wp_get_db_schema()" function was not defined. ' );
65
65
}
66
66
$ 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 ' );
69
75
if ( $ create_node && $ create_node ->has_child_node ( 'createTable ' ) ) {
70
76
$ name_node = $ create_node ->get_first_descendant_node ( 'tableName ' );
71
77
$ name = $ this ->unquote_mysql_identifier (
@@ -86,7 +92,10 @@ public function ensure_correct_information_schema(): void {
86
92
} else {
87
93
// Other table (a WordPress plugin or unrelated to WordPress).
88
94
$ 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
+ }
90
99
}
91
100
$ this ->information_schema_builder ->record_create_table ( $ ast );
92
101
}
@@ -96,7 +105,10 @@ public function ensure_correct_information_schema(): void {
96
105
foreach ( $ information_schema_tables as $ table ) {
97
106
if ( ! in_array ( $ table , $ tables , true ) ) {
98
107
$ 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
+ }
100
112
$ this ->information_schema_builder ->record_drop_table ( $ ast );
101
113
}
102
114
}
0 commit comments