@@ -64,12 +64,16 @@ 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- $ parts = preg_split ( '/(CREATE\s+TABLE)/ ' , $ schema , -1 , PREG_SPLIT_NO_EMPTY );
68- foreach ( $ parts as $ part ) {
69- $ name = $ this ->unquote_mysql_identifier (
70- preg_split ( '/\s+/ ' , $ part , 2 , PREG_SPLIT_NO_EMPTY )[0 ]
71- );
72- $ wp_tables [ $ name ] = 'CREATE TABLE ' . $ part ;
67+ foreach ( $ this ->driver ->parse_query ( $ schema ) as $ query ) {
68+ $ create_node = $ query ->get_first_descendant_node ( 'createStatement ' );
69+ if ( $ create_node && $ create_node ->has_child_node ( 'createTable ' ) ) {
70+ $ name_node = $ create_node ->get_first_descendant_node ( 'tableName ' );
71+ $ name = $ this ->unquote_mysql_identifier (
72+ substr ( $ schema , $ name_node ->get_start (), $ name_node ->get_length () )
73+ );
74+
75+ $ wp_tables [ $ name ] = $ create_node ;
76+ }
7377 }
7478 }
7579
@@ -78,12 +82,12 @@ public function ensure_correct_information_schema(): void {
7882 if ( ! in_array ( $ table , $ information_schema_tables , true ) ) {
7983 if ( isset ( $ wp_tables [ $ table ] ) ) {
8084 // WordPress core table (as returned by "wp_get_db_schema()").
81- $ sql = $ wp_tables [ $ table ];
85+ $ ast = $ wp_tables [ $ table ];
8286 } else {
8387 // Other table (a WordPress plugin or unrelated to WordPress).
8488 $ sql = $ this ->generate_create_table_statement ( $ table );
89+ $ ast = $ this ->driver ->parse_query ( $ sql )->current ();
8590 }
86- $ ast = $ this ->driver ->parse_query ( $ sql );
8791 $ this ->information_schema_builder ->record_create_table ( $ ast );
8892 }
8993 }
@@ -92,7 +96,7 @@ public function ensure_correct_information_schema(): void {
9296 foreach ( $ information_schema_tables as $ table ) {
9397 if ( ! in_array ( $ table , $ tables , true ) ) {
9498 $ sql = sprintf ( 'DROP %s ' , $ this ->quote_sqlite_identifier ( $ table ) );
95- $ ast = $ this ->driver ->parse_query ( $ sql );
99+ $ ast = $ this ->driver ->parse_query ( $ sql )-> current () ;
96100 $ this ->information_schema_builder ->record_drop_table ( $ ast );
97101 }
98102 }
0 commit comments