@@ -284,7 +284,7 @@ class WP_SQLite_Information_Schema_Builder {
284284 'utf16 ' => 'utf16_general_ci ' ,
285285 'utf16le ' => 'utf16le_general_ci ' ,
286286 'utf32 ' => 'utf32_general_ci ' ,
287- 'utf8 ' => 'utf8_general_ci ' ,
287+ 'utf8mb3 ' => 'utf8mb3_general_ci ' ,
288288 'utf8mb4 ' => 'utf8mb4_0900_ai_ci ' , // @TODO: This should probably be version-dependent.
289289 // Before MySQL 8, the default was different.
290290 );
@@ -308,7 +308,7 @@ class WP_SQLite_Information_Schema_Builder {
308308 'utf16 ' => 4 ,
309309 'utf16le ' => 4 ,
310310 'utf32 ' => 4 ,
311- 'utf8 ' => 3 ,
311+ 'utf8mb3 ' => 3 ,
312312 'utf8mb4 ' => 4 ,
313313 );
314314
@@ -430,7 +430,7 @@ public function get_computed_information_schema_table_definition( string $table_
430430 FROM (
431431 VALUES
432432 ('binary', 'binary', 'Binary pseudo charset', 1),
433- ('utf8 ', 'utf8_general_ci ', 'UTF-8 Unicode', 3),
433+ ('utf8mb3 ', 'utf8mb3_general_ci ', 'UTF-8 Unicode', 3),
434434 ('utf8mb4', 'utf8mb4_0900_ai_ci', 'UTF-8 Unicode', 4)
435435 ) " ;
436436 case 'collations ' :
@@ -445,9 +445,9 @@ public function get_computed_information_schema_table_definition( string $table_
445445 FROM (
446446 VALUES
447447 ('binary', 'binary', 63, 'Yes', 'Yes', 1, 'NO PAD'),
448- ('utf8_bin ', 'utf8 ', 83, '', 'Yes', 1, 'PAD SPACE'),
449- ('utf8_general_ci ', 'utf8 ', 33, 'Yes', 'Yes', 1, 'PAD SPACE'),
450- ('utf8_unicode_ci ', 'utf8 ', 192, '', 'Yes', 8, 'PAD SPACE'),
448+ ('utf8mb3_bin ', 'utf8mb3 ', 83, '', 'Yes', 1, 'PAD SPACE'),
449+ ('utf8mb3_general_ci ', 'utf8mb3 ', 33, 'Yes', 'Yes', 1, 'PAD SPACE'),
450+ ('utf8mb3_unicode_ci ', 'utf8mb3 ', 192, '', 'Yes', 8, 'PAD SPACE'),
451451 ('utf8mb4_bin', 'utf8mb4', 46, '', 'Yes', 1, 'PAD SPACE'),
452452 ('utf8mb4_unicode_ci', 'utf8mb4', 224, '', 'Yes', 8, 'PAD SPACE'),
453453 ('utf8mb4_0900_ai_ci', 'utf8mb4', 255, 'Yes', 'Yes', 0, 'NO PAD')
@@ -2022,7 +2022,7 @@ private function get_table_collation( WP_Parser_Node $node ): string {
20222022 // @TODO: Use default DB collation or DB_CHARSET & DB_COLLATE.
20232023 return 'utf8mb4_0900_ai_ci ' ;
20242024 }
2025- return strtolower ( $ this ->get_value ( $ collate_node ) );
2025+ return $ this -> normalize_collation_name ( strtolower ( $ this ->get_value ( $ collate_node ) ) );
20262026 }
20272027
20282028 /**
@@ -2360,20 +2360,17 @@ private function get_column_data_types( WP_Parser_Node $node ): array {
23602360 $ full_type .= '( ' . implode ( ', ' , $ values ) . ') ' ;
23612361 }
23622362
2363- $ field_length = $ type_node ->get_first_descendant_node ( 'fieldLength ' );
2364- if ( null !== $ field_length ) {
2363+ $ field_length = $ type_node ->get_first_descendant_node ( 'fieldLength ' );
2364+ $ is_integer_type = in_array ( $ type , array ( 'tinyint ' , 'smallint ' , 'mediumint ' , 'int ' , 'bigint ' ), true );
2365+ $ is_boolean_type = null !== $ field_length && 'tinyint ' === $ type && '(1) ' === $ this ->get_value ( $ field_length );
2366+ $ has_zerofill = null !== $ type_node ->get_first_descendant_token ( WP_MySQL_Lexer::ZEROFILL_SYMBOL );
2367+ $ stores_type_size = ! $ is_integer_type || $ is_boolean_type || $ has_zerofill ;
2368+ if ( null !== $ field_length && $ stores_type_size ) {
23652369 if ( 'decimal ' === $ type || 'float ' === $ type || 'double ' === $ type ) {
23662370 $ full_type .= rtrim ( $ this ->get_value ( $ field_length ), ') ' ) . ',0) ' ;
23672371 } else {
23682372 $ full_type .= $ this ->get_value ( $ field_length );
23692373 }
2370- /*
2371- * As of MySQL 8.0.17, the display width attribute is deprecated for
2372- * integer types (tinyint, smallint, mediumint, int/integer, bigint)
2373- * and is not stored anymore. However, it may be important for older
2374- * versions and WP's dbDelta, so it is safer to keep it at the moment.
2375- * @TODO: Investigate if it is important to keep this.
2376- */
23772374 }
23782375
23792376 $ precision = $ type_node ->get_first_descendant_node ( 'precision ' );
@@ -2463,27 +2460,27 @@ private function get_column_charset_and_collation( WP_Parser_Node $node, string
24632460 $ is_binary = true ;
24642461 }
24652462 } else {
2466- // National charsets (in MySQL, it's "utf8") .
2463+ // National charsets use the three-byte UTF-8 character set .
24672464 $ data_type_node = $ node ->get_first_descendant_node ( 'dataType ' );
24682465 if (
24692466 $ data_type_node ->has_child_node ( 'nchar ' )
24702467 || $ data_type_node ->has_child_token ( WP_MySQL_Lexer::NCHAR_SYMBOL )
24712468 || $ data_type_node ->has_child_token ( WP_MySQL_Lexer::NATIONAL_SYMBOL )
24722469 || $ data_type_node ->has_child_token ( WP_MySQL_Lexer::NVARCHAR_SYMBOL )
24732470 ) {
2474- $ charset = 'utf8 ' ;
2471+ $ charset = 'utf8mb3 ' ;
24752472 }
24762473 }
24772474
24782475 // Normalize charset.
2479- if ( ' utf8mb3 ' = == $ charset ) {
2480- $ charset = ' utf8 ' ;
2476+ if ( null ! == $ charset ) {
2477+ $ charset = $ this -> normalize_charset_name ( $ charset ) ;
24812478 }
24822479
24832480 // Collation.
24842481 $ collation_node = $ node ->get_first_descendant_node ( 'collationName ' );
24852482 if ( null !== $ collation_node ) {
2486- $ collation = strtolower ( $ this ->get_value ( $ collation_node ) );
2483+ $ collation = $ this -> normalize_collation_name ( strtolower ( $ this ->get_value ( $ collation_node ) ) );
24872484 }
24882485
24892486 // Defaults.
@@ -2510,6 +2507,29 @@ private function get_column_charset_and_collation( WP_Parser_Node $node, string
25102507 return array ( $ charset , $ collation );
25112508 }
25122509
2510+ /**
2511+ * Normalize a character set to its modern MySQL name.
2512+ *
2513+ * @param string $charset The character set name.
2514+ * @return string The normalized character set name.
2515+ */
2516+ private function normalize_charset_name ( string $ charset ): string {
2517+ return 'utf8 ' === $ charset ? 'utf8mb3 ' : $ charset ;
2518+ }
2519+
2520+ /**
2521+ * Normalize a collation to its modern MySQL name.
2522+ *
2523+ * @param string $collation The collation name.
2524+ * @return string The normalized collation name.
2525+ */
2526+ private function normalize_collation_name ( string $ collation ): string {
2527+ if ( 0 === strpos ( $ collation , 'utf8_ ' ) ) {
2528+ return 'utf8mb3_ ' . substr ( $ collation , 5 );
2529+ }
2530+ return $ collation ;
2531+ }
2532+
25132533 /**
25142534 * Extract column length info from the "columnDefinition" or "fieldDefinition" AST node.
25152535 *
0 commit comments