WordPress.org

Make WordPress Core

#21045 closed defect (bug) (duplicate)

wpdb update() fails to write float values when non-english locale is enabled

Reported by: Alexis2004 Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4
Component: Database Keywords:
Focuses: Cc:

Description

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.

Change History (2)

comment:1 knutsp22 months ago

  • Cc knut@… added

comment:2 scribu22 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.