[wp-trac] [WordPress Trac] #19861: $wpdb->prepare() fails with localized floats

WordPress Trac wp-trac at lists.automattic.com
Fri Jun 22 09:39:18 UTC 2012


#19861: $wpdb->prepare() fails with localized floats
----------------------------------------+--------------------
 Reporter:  laotse                      |       Owner:
     Type:  defect (bug)                |      Status:  new
 Priority:  normal                      |   Milestone:  3.5
Component:  Database                    |     Version:  3.3.1
 Severity:  normal                      |  Resolution:
 Keywords:  needs-unit-tests has-patch  |
----------------------------------------+--------------------

Comment (by SergeyBiryukov):

 To summarize, this is the snippet (based on #21045) that I've tested the
 issue with:
 {{{
 setlocale( LC_ALL, array( 'ru_RU.utf8', 'rus' ) );
 $wpdb->update(
         'test_table',
         array( 'float_column' => 0.7 ),
         array( 'meta_id' => 5 ),
         array( '%f' ),
         array( '%d' )
 );
 }}}
 This results in the error:
 {{{
 WordPress database error: [You have an error in your SQL syntax; check the
 manual that corresponds to your MySQL server version for the right syntax
 to use near '000000 WHERE `meta_id` = 5' at line 1]
 UPDATE `test_table` SET `float_column` = 0,000000 WHERE `meta_id` = 5
 }}}
 With [attachment:19861.patch], there's no error, but the value passed to
 `$wpdb->prepare()` is still incorrect (0,7 instead of 0.7), so it's not
 converted properly. The resulting query is:
 {{{
 UPDATE `test_table` SET `float_column` = 0.000000 WHERE `meta_id` = 5
 }}}
 [attachment:19861.2.patch] is an attempt to fix that. The proper query
 would be:
 {{{
 UPDATE `test_table` SET `float_column` = 0.700000 WHERE `meta_id` = 5
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/19861#comment:9>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list