[wp-trac] [WordPress Trac] #21045: wpdb update() fails to write float values when non-english locale is enabled
WordPress Trac
wp-trac at lists.automattic.com
Fri Jun 22 06:53:22 UTC 2012
#21045: wpdb update() fails to write float values when non-english locale is
enabled
--------------------------+-----------------------------
Reporter: Alexis2004 | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Database | Version: 3.4
Severity: normal | Keywords:
--------------------------+-----------------------------
When I set non-English locale in wp-config.php:
{{{
setlocale(LC_ALL, array('ru_RU.utf8', 'rus'));
}}}
and trying to update float column view via $wpdb->update() method:
{{{
$wpdb->update(
...,
array(
'float_column' => 0.5
),
...,
array(
'%f'
),
...
);
}}}
the query is silently failed to execute.
The reason of it is that Russian language has different floating point
separator (comma instead of point) and sprintf() function formats query
using this locale settings. But comma is not valid floating point
separator to MySQL database engine.
In my opinion there are 2 different method to solve this problem:
1) Save current locale before generating query, revert it to default
English locale, make query and then revert saved locale back.
2) Treat %f formatting directive as %F (non-locale aware version of %f) --
just do replace in $wpdb->update() method. There is no reasonable cause to
use %f instead of %F in SQL formatting, but a lot of plugins still use %f
as format modifier and it's easier to make change to core instead of
contacting each plugins author.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/21045>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list