@@ -3352,16 +3352,14 @@ private function execute_show() {
3352
3352
3353
3353
foreach ( $ columns as $ column ) {
3354
3354
$ column = (array ) $ column ;
3355
+ $ mysql_type = $ this ->get_cached_mysql_data_type ( $ table_name , $ column ['Field ' ] );
3355
3356
$ definition = '' ;
3356
3357
$ definition .= '` ' . $ column ['Field ' ] . '` ' ;
3357
- $ definition .= $ this ->get_cached_mysql_data_type (
3358
- $ table_name ,
3359
- $ column ['Field ' ]
3360
- ) ?? $ column ['Type ' ];
3358
+ $ definition .= $ mysql_type ?? $ column ['Type ' ];
3361
3359
$ definition .= 'PRI ' === $ column ['Key ' ] ? ' PRIMARY KEY ' : '' ;
3362
3360
$ definition .= 'PRI ' === $ column ['Key ' ] && 'INTEGER ' === $ column ['Type ' ] ? ' AUTO_INCREMENT ' : '' ;
3363
3361
$ definition .= 'NO ' === $ column ['Null ' ] ? ' NOT NULL ' : '' ;
3364
- $ definition .= $ column [ ' Default ' ] ? ' DEFAULT ' . $ column[ ' Default ' ] : '' ;
3362
+ $ definition .= $ this -> get_column_default ( $ column, $ mysql_type ) ;
3365
3363
$ entries [] = $ definition ;
3366
3364
}
3367
3365
foreach ( $ keys as $ key ) {
@@ -3533,6 +3531,21 @@ function ( $row ) use ( $name_map ) {
3533
3531
return $ columns ;
3534
3532
}
3535
3533
3534
+ /**
3535
+ * Gets the column default.
3536
+ *
3537
+ * @param array $column The table column
3538
+ *
3539
+ * @return string Prepared default value for the column.
3540
+ */
3541
+ private function get_column_default ( $ column , $ mysql_type ) {
3542
+ if ( $ column ['Default ' ] && ! in_array ( strtolower ( $ mysql_type ), array ( 'datetime ' , 'date ' , 'time ' , 'timestamp ' , 'year ' ), true ) ) {
3543
+ return ' DEFAULT ' . $ column ['Default ' ];
3544
+ } else {
3545
+ return '' ;
3546
+ }
3547
+ }
3548
+
3536
3549
/**
3537
3550
* Consumes data types from the query.
3538
3551
*
0 commit comments