Skip to content

Commit be2841d

Browse files
committed
Improve and document default column value detection
1 parent 231bab2 commit be2841d

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

wp-includes/sqlite-ast/class-wp-sqlite-information-schema-reconstructor.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,27 @@ private function column_has_default( string $mysql_type, ?string $default_value
369369
if ( null === $default_value || '' === $default_value ) {
370370
return false;
371371
}
372+
$mysql_type = strtolower( $mysql_type );
373+
374+
/*
375+
* In MySQL, geometry columns can't have a default value.
376+
*
377+
* Geometry columns are saved as TEXT in SQLite, and in an older version
378+
* of the SQLite driver, TEXT columns were assigned a default value of ''.
379+
*/
380+
if ( 'geomcollection' === $mysql_type || 'geometrycollection' === $mysql_type ) {
381+
return false;
382+
}
383+
384+
/*
385+
* In MySQL, date/time columns can't have a default value of ''.
386+
*
387+
* Date/time columns are saved as TEXT in SQLite, and in an older version
388+
* of the SQLite driver, TEXT columns were assigned a default value of ''.
389+
*/
372390
if (
373391
"''" === $default_value
374-
&& in_array( strtolower( $mysql_type ), array( 'datetime', 'date', 'time', 'timestamp', 'year' ), true )
392+
&& in_array( $mysql_type, array( 'datetime', 'date', 'time', 'timestamp', 'year' ), true )
375393
) {
376394
return false;
377395
}

0 commit comments

Comments
 (0)