[wp-trac] [WordPress Trac] #28591: dbDelta Non-literal DEFAULT not working (CURRENT_TIMESTAMP)
WordPress Trac
noreply at wordpress.org
Thu Jun 19 19:38:53 UTC 2014
#28591: dbDelta Non-literal DEFAULT not working (CURRENT_TIMESTAMP)
--------------------------+------------------------------
Reporter: sc0ttkclark | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Comment (by sc0ttkclark):
Here's an idea for at line 1672 in upgrade.php, but it can be further
improved for sure.
{{{
$cquery = null;
// Get the default value from the array
//echo "{$cfields[strtolower($tablefield->Field)]}<br>";
if (preg_match("| DEFAULT '(.*?)'|i",
$cfields[strtolower($tablefield->Field)], $matches)) {
$default_value = $matches[1];
if ($tablefield->Default != $default_value) {
// Add a query to change the column's default value
$cquery = "ALTER TABLE {$table} ALTER COLUMN
{$tablefield->Field} SET DEFAULT '{$default_value}'";
$for_update[$table.'.'.$tablefield->Field] = "Changed
default value of {$table}.{$tablefield->Field} from {$tablefield->Default}
to {$default_value}";
}
}
// Check for default non-literals
preg_match("| DEFAULT (\w*)|i", $cfields[strtolower($tablefield->Field)],
$non_literal_matches);
// Is actual field type different from the field type in query?
if ($tablefield->Type != $fieldtype || $non_literal_matches) {
// Add a query to change the column type
$cquery = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field}
" . $cfields[strtolower($tablefield->Field)];
if ( $tablefield->Type != $fieldtype ) {
$for_update[$table.'.'.$tablefield->Field] = "Changed type
of {$table}.{$tablefield->Field} from {$tablefield->Type} to " .
$cfields[strtolower($tablefield->Field)];
}
else {
$for_update[$table.'.'.$tablefield->Field] = "Changed
definition of {$table}.{$tablefield->Field} to " .
$cfields[strtolower($tablefield->Field)];
}
}
if ( $cquery ) {
$cqueries[] = $cquery;
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/28591#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list