Download & Extend

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

Project:Gallery
Version:6.x-1.x-dev
Component:Miscellaneous
Category:bug report
Priority:critical
Assigned:Unassigned
Status:active

Issue Summary

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

Comments

#1

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

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

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.

#4

#5

The module here (http://drupal.org/node/801112#comment-3835900) attempts to fix this (and does in my cases) by resetting the locale LC_NUMERIC format in several places. It may work for folks who are experiencing this problem.

#6

#7

By the way, as it turned out my issue was caused by a content editor who had PHP filter access setting the locale in a block :S