Skip to content

Commit a18ec4e

Browse files
committed
Ensure that for empty default date fields there is no default
1 parent 929d908 commit a18ec4e

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

wp-includes/sqlite/class-wp-sqlite-translator.php

+18-5
Original file line numberDiff line numberDiff line change
@@ -3352,16 +3352,14 @@ private function execute_show() {
33523352

33533353
foreach ( $columns as $column ) {
33543354
$column = (array) $column;
3355+
$mysql_type = $this->get_cached_mysql_data_type( $table_name, $column['Field'] );
33553356
$definition = '';
33563357
$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'];
33613359
$definition .= 'PRI' === $column['Key'] ? ' PRIMARY KEY' : '';
33623360
$definition .= 'PRI' === $column['Key'] && 'INTEGER' === $column['Type'] ? ' AUTO_INCREMENT' : '';
33633361
$definition .= 'NO' === $column['Null'] ? ' NOT NULL' : '';
3364-
$definition .= $column['Default'] ? ' DEFAULT ' . $column['Default'] : '';
3362+
$definition .= $this->get_column_default( $column, $mysql_type );
33653363
$entries[] = $definition;
33663364
}
33673365
foreach ( $keys as $key ) {
@@ -3533,6 +3531,21 @@ function ( $row ) use ( $name_map ) {
35333531
return $columns;
35343532
}
35353533

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+
35363549
/**
35373550
* Consumes data types from the query.
35383551
*

0 commit comments

Comments
 (0)