[wp-trac] [WordPress Trac] #28591: dbDelta Non-literal DEFAULT not working (CURRENT_TIMESTAMP)
WordPress Trac
noreply at wordpress.org
Thu Jun 19 19:38:04 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 | Keywords:
Focuses: |
--------------------------+-----------------------------
Using dbDelta and any internal SQL values like CURRENT_TIMESTAMP won't
work because dbDelta matches based on this regex:
{{{
"| DEFAULT '(.*?)'|i"
}}}
The block current looks like this:
{{{
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
$cqueries[] = "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}";
}
}
}}}
I'm not sure what the best solution is for this, but perhaps it should be:
1. Check if there is a default to change, if there is -- store default
alter query, don't add to $cqueries[] yet
2. Check if there is a field type change OR a default non-literal found,
if there is -- use this CHANGE COLUMN query instead of the 'default'
changing query in point 1
Does that sound like a good solution here?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/28591>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list