setlocale() calls in Gallery wrongly transform float numbers in SQL

jenger1965 - March 3, 2009 - 08:40
Project:Gallery
Version:6.x-1.x-dev
Component:Miscellaneous
Category:bug report
Priority:critical
Assigned:Unassigned
Status:active
Description

Please refer to drupal bug

http://drupal.org/node/387374

gallery2 changes locale via setlocale(LC_ALL,country).
If the "LC_NUMERIC" is set to ',' , e.g. by german locale 'de_DE', D5 "modules/search.module" fails
in SQL queries containing float numbers (score).
German formated floats "3,1415" appear in the SQL statements,
that isn't valid SQL syntax, it should be "3.1415"

To preserve the correct LC_NUMERIC state, call setlocale(LC_NUMERIC,"C") somewhere in
the "modules/gallery.module", after initialization of G2.

Regards Jens

#1

inforeto - April 29, 2009 - 02:20
Priority:normal» critical

changing to critical since it breaks the search indexing in cron.
the conclusion from other issues is that modules responsability to not change setlocale, so it is ok to add the fix within this module and not core.

now, where exactly is the initialization code needed or what hook to use?

#2

inforeto - April 29, 2009 - 04:33

Added the following line by the end of function _gallery_init() in gallery_base.inc:

$somebase = setlocale(LC_NUMERIC, 'C');

When testing this make sure not to make a syntax error as the error message is the same as with a broken php node or module, similar to this:

Error in function 'eval()' (common.inc(1464) : eval()'d code:5):

* Unable to initialize embedded Gallery

In my case i had to lower the maximum nodes per cron run to the minimum of 10 and then it finished indexing.
But it worked for purposes of stopping the pair of locale float errors.
If someone can test and search for side issues it'd be appreciated.

#3

Dave Reid - September 7, 2009 - 03:55
Title:Bad SQL float number on locales "de_DE"» setlocale() calls in Gallery wrongly transform float numbers in SQL
Version:5.x-2.2» 6.x-1.x-dev

This is a problem will any Gallery install since the setlocale is called from the actual Gallery code. We've had this problem pop up in the XML sitemap issue queue and all the people had Gallery2 installed. Transforming floats from 0.5 to '0,5' causes SQL to fail, especially if a module tries to install a schema that has a field with a default float value. Horrible horrible stuff.

 
 

Drupal is a registered trademark of Dries Buytaert.