Make WordPress Core

Opened 12 years ago

Closed 12 years ago

#21045 closed defect (bug) (duplicate)

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

Reported by: alexis2004's profile 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)

#1 @knutsp
12 years ago

  • Cc knut@… added

#2 @scribu
12 years ago

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