View ProjeQtOr On SourceForge.net
ProjeQtOr - Project Management Tool
Support us on Capterra
OIN - Open Invention Network
ProjeQtOr free project management software - Implicit float to string conversion leads to database incorrect SQL update - ProjeQtOr
 
 

Implicit float to string conversion leads to database incorrect SQL update

More
26 Jan 2015 13:50 - 26 Jan 2015 14:03 #1 by michel.guillot
We're using Projeqtor version 4.5.4 and french language browsers.

In the last week or so we began to notice erroneous behaviour when submitting data - real work input. At that time we were using version 4.5.3 but updating to version 4.5.4 didn't solve the issue. The problem arises when decimal values are input - eg 0,6 would result in 0 being saved in the database.

First I changed MySQL configuration so as to prevent incorrect data being saved in the database (STRICT_ALL_TABLES) because I suspected this was related to a comma/point issue as we were using the french language and the issue only happened with decimal numbers. From there on, we got the attached eror message from Projeqtor when things were going bad. At least the database was not corrupted and we could retry the data update until we succeeded.



By retrying we would finally be able to save the data ! All this was reminding me of an issue we got last year and for which I submitted a post: Work allocation in half-days

I don't have a clue why we seem to get the same problem again because I didn't change the Apache configuration nor TRAC configuration and there was no software update for both in the last weeks...

Anyway I traced the problem to the following line of code (/model/persistence/SqlElement.php: line 793) :
$col_new_value=trim($col_new_value);

$col_new_value is of type float when input into the trim function then becomes a string when it receives value from the output of the said trim function. As that function expects a string as input parameter, there is an implicit float to string conversion which depends on the locale defined at the time the trim function is called. When the locale is a french one, the float is converted to '0,6' whereas when the locale is an english one the float is converted to '0.6'.

When a comma appears as a result of the implicit float to string conversion the SQL query which is built from it to update the mySQL database either saves the value 0 (the integer part of 0,6) when mySQL mode is not strict or fails with an error otherwise.

To make a fast patch I added the following line of code just after the previous one:
$col_new_value=str_replace(',', '.', $col_new_value);

This is just a fast patch and I guess you will bring a better global solution to this issue. At least it seems to me abnormal to apply the trim function to a float !

I didn't find setlocale() calls in the source code so I wonder how the PHP code gets its locale. I tried to modify the locale definition at the Apache level but that didn't seem to have any impact on the locale used for the float to string conversion. As localization is handled at the Dojo level if I'm correct, and input values are always transmitted to the server as strings with decimal points - not commas, wouldn't it be safer to explicitly set the locale in the PHP code ?

Regards
Attachments:
Last edit: 26 Jan 2015 14:03 by michel.guillot. Reason: New details and question

Please Log in or Create an account to join the conversation.

More
27 Jan 2015 11:41 #2 by babynus
Hi,

Thanks for this clearly detailed analysis of the issue.

what is very strange is that I cannot reproduce.
I use french locale and can save 0,1 d without issue on V4.5.4.

Could you :
1) try and clean browser cache and try again (maybe you did this already)
2) try and reproduce on demo (demo.projeqtor.org)
3) try with another brower (which browser are you using ?)

Babynus
Administrator of ProjeQtOr web site

Please Log in or Create an account to join the conversation.

More
27 Jan 2015 11:49 #3 by babynus
Hi,

Additional question :
Do you reproduce this issue only on Real Work allocation ?
Could you for instance try and define decimal work on an activity ?

Babynus
Administrator of ProjeQtOr web site

Please Log in or Create an account to join the conversation.

More
15 Feb 2015 13:26 #4 by babynus
I could not reproduce whatever I try.

I included patch as proposed, to ensure data is always correct, with one extra test to avoid replacing , with . in text fields :
if ($dataType=='decimal') {
    $col_new_value=str_replace(',', '.', $col_new_value);
}

Patch included in V4.5.5 (patch to come very soon)

Babynus
Administrator of ProjeQtOr web site

Please Log in or Create an account to join the conversation.

More
17 Feb 2015 09:10 #5 by michel.guillot
Hi babynus,

I'm not in the position of answering your questions regarding reproducing the issue on Real Work allocation and activity because the issue has gone for me after restarting my virtual machine. I guess some updates got active as a result of it. I didn't make a clear link between those updates and Projeqtor, unfortunately.This was 3 weeks ago and since then we didn't notice the issue anymore.

Thank you babynus for trying to reproduce the issue and for patching the code for the implicit float to string conversion. I will come back to you if the issue occurs again.

Regards

Please Log in or Create an account to join the conversation.

Moderators: babynusprotion
Time to create page: 0.053 seconds

Cookies settings

×

Functional Cookies

Ce site utilise des cookies pour assurer son bon fonctionnement et ne peuvent pas être désactivés de nos systèmes. Nous ne les utilisons pas à des fins publicitaires. Si ces cookies sont bloqués, certaines parties du site ne pourront pas fonctionner.

Session

Please login to see yours activities!

Other cookies

Ce site web utilise un certain nombre de cookies pour gérer, par exemple, les sessions utilisateurs.