-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug #46408: Fix double formatting for PostgreSQL bound parameters #186
Conversation
@@ -1736,7 +1737,15 @@ static void _php_pgsql_free_params(char **params, int num_params) | |||
} else { | |||
zval tmp_val = **tmp; | |||
zval_copy_ctor(&tmp_val); | |||
|
|||
// PSQL requires . for radix; convert to string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use '/* */' instead of '//'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done: asmecher@823ddbf
While this fix sure does what it needs to do to address this problem, I’m not sure we should work around this design flaw on every single occasion. Additionally the bugfix misses a test to make sure we don’t get a regression at some point. |
|
||
/* PSQL requires . for radix; convert to string, avoiding problems with doubles | ||
and locales using , as a radix character instead (see bug #46408) */ | ||
char *current_locale = setlocale(LC_NUMERIC, "C"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we use C89/C90, declarations may not be mixed with code. Please move the declaration to the beginning of the block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally: are you certain this works on any platform we support?
Thanks for the hints, Lars -- I've moved the var declaration to the head of the block, added #ifdef checks to make sure HAVE_SETLOCALE is respected, and added a regression test (ext/pgsql/tests/bug46408.phpt). I haven't contributed code to PHP before so your scrutiny is appreciated. |
As for whether or not this problem should be worked around in PHP, it's necessary either to do it there or to do it in my own PHP scripts (and for everyone else who needs both setlocale and pg_query_params). I agree that it's not ideal but it does rehabilitate that function; I wouldn't know what to suggest as a broader strategy. Note that the test will require the hr_HR locale to be generated on the test system (see /etc/locale.gen). |
Alright, digged a little deeper into this issue and here is my first analysis. The code flow basically goes like this
This means: we need something like |
Thanks for the feedback, Lars -- I've introduced convert_to_string_unlocalized and used it instead. I've attempted to keep code duplication to a minimum -- personally, I would have preferred to introduce an optional parameter to the existing _convert_to_string but I suspect that would not follow PHP coding conventions. |
What about convert_to_cstring (like in c locale?) Btw: regarding locale, you could also try to iterate over a few variants (de_DE e.g. also uses "," as a decimal separator). |
Agreed; changed. |
Just so that you know, I've written a mail to internals@php.net to get more people into this discussion: http://marc.info/?l=php-internals&m=134807980716416&w=2 |
Thanks, Lars. This has been helpful and informative for me and I hope it results in an accepted fix. |
Unfortunately that round on the php-internals list wasn't too encouraging. What would you suggest for next steps? I'd like to see a general fix applied, but the idea didn't seem popular. Alternately, I could alter this to just affect pg_query_params, but that won't help maintainability going forward. |
@@ -23,6 +23,7 @@ | |||
/* $Id$ */ | |||
|
|||
#include <stdlib.h> | |||
#include <locale.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why you need locale.h?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's no longer needed.
Could you squash the commits. I will apply your fix for the PHP 5.5 branch. |
Done. Thanks for all your help, Lars. |
Comment on behalf of lstrojny at php.net: Merged into 5.5 and master. Thanks for your contribution and your patience! |
See https://bugs.php.net/bug.php?id=46408 for extensive discussion of this.