From: Ben C. <bcl...@pe...> - 2004-12-30 10:52:29
|
Ok. When ever the CGI or SQL is called with floats, I will: setlocale(LC_NUMERIC, "POSIX"); sprintf(sql, "INSERT data = %f", 0.17); setlocale(LC_NUMERIC, ""); Since there are users battling this problem now. And this will corrupt the database. I'll have to do this now. The summary tables will wait a day. None of your work is with the CGI or SQL today? Ben Yves wrote: >>Hi Yves, >> >>The problem is not with MySQL but with 'c'. The language translation >>introduced a line of code which forces the 'format' to output floating >>numbers in local format: >> >>printf("%f", 0.17) -> "0,17" > > > OK :) > > > > >>1. The 'atof' is not locale safe. 0,17 -> 0.00 > > > I suppose that strtof and strtod are not locale safe either. > > >>2. The interface to the database. DBMS expects numbers in POSIX format: >> >>"INSERT (1,17)" is understood as "INSERT ('1', '17')" >>"INSERT ('1,17')" is understood as "INSERT ('1'); >> >>Users with this version in these countries are therefore sending corrupt >>data to their database. Eg, 'show_load' will be storing only the >>integer part of the numbers. THIS IS BAD! > > > I agree :) > > >>3. The HTML CGI interface. Floating numbers are likely to be >>corruption as above. >> >> >>The hack I suggested will fix this: >> >>setlocale(LC_NUMERIC, "POSIX"); >> >>But it may be a little too blunt. > > > Correct as a quick fix. > > >>So what do we do? >> >>1. Set locale to "POSIX" and loose the localized display? > > > no :) > > >>2. Set locale to "POSIX" before any SQL, and back to "" afterwards: >> >>setlocale(LC_NUMERIC, "POSIX"); >>sprintf(sql, "INSERT data = %f", 0.17); >>setlocale(LC_NUMERIC, ""); > > > yes, maybe this is best. > > >>3. Set the locale to "POSIX" for all the code, accept the presentation. >> Here and here only, set back to "": >> >>setlocale(LC_NUMERIC, ""); >>printf("Graph label: %f", 0.17); >>setlocale(LC_NUMERIC, "POSIX"); > > > Probably more to print than floats to send to the database. 2 is better. > > Yves -- Ben Clewett bcl...@pe... PerfParse http://www.perfparse.org PP FAQ http://wiki.perfparse.org/tiki-list_faqs.php |