Edit report at https://bugs.php.net/bug.php?id=46408&edit=1
ID: 46408 User updated by: alec at smecher dot bc dot ca Reported by: alec at smecher dot bc dot ca Summary: Locale number format settings can cause pg_query_params to break with numerics Status: Wont fix Type: Bug Package: PostgreSQL related Operating System: * PHP Version: 5.*, 6 Assigned To: yohgaki Block user comment: N Private report: N New Comment: Your example of storing a string-formatted double in a varchar column strikes me as an unusual case involving a type mismatch, and can be worked around clearly and logically by passing "$number" in rather than $number. If this isn't going to be fixed, there should at least be documentation in the manual for pg_query_params: "If binding numeric data for use as numeric data, make sure you first cast it to a string using '.' for a decimal separator." But that makes no sense at all to me. Meanwhile, this same issue has been solved elsewhere as I've suggested. Gnome: https://bugzilla.gnome.org/show_bug.cgi?id=650016 Pear::DB: http://pear.php.net/bugs/bug.php?id=3021 It's also implemented in these other cases with specific number formatting code as I believe it should: Pear::MDB2: http://svn.php.net/viewvc/pear/packages/MDB2/trunk/MDB2/Driver/Datatype/Common.php?view=markup#l1498 mysqli: https://github.com/php/php-src/blob/master/ext/mysqli/mysqli_api.c#L102 "PostgreSQL users are supposed to pass/recieve data via strings *always* with C/C++ API." -- this is also incorrect, if I understand you properly. See the paramTypes column documented here http://www.postgresql.org/docs/9.1/static/libpq-exec.html for the PQexecParams function that you're using. Previous Comments: ------------------------------------------------------------------------ [2012-04-17 21:36:47] yohg...@php.net PostgreSQL users are supposed to pass/recieve data via strings *always* with C/C++ API. Programmers are responsible how it's passed. As as mentioned already, system will not know how numbers should be formatted for certain column. The code even don't care the column types of tables. Think, create table test (a text); and insert into test (a) values ("number"); The number format is decided by PHP programmer, not pgsql module. ------------------------------------------------------------------------ [2012-04-17 20:15:02] alec at smecher dot bc dot ca That's not correct. In the supplied example, the data is provided to pg_query_params as numeric data. The number to string conversion is done within pg_query_params (here, I think: https://github.com/php/php-src/blob/master/ext/pgsql/pgsql.c#L1739). ------------------------------------------------------------------------ [2012-04-17 20:06:10] yohg...@php.net >PostgreSQL is hard-coded to parse numeric values using "." as the decimal >point (see >https://github.com/postgres/postgres/blob/master/src/backend/utils/adt/numeric. >c in set_var_from_str for implementation). The number *may* be a string, what we should do then? Is it "3.5" or "3,5"? Only the PHP programmer who is writing the code knew which should be. Therefore, this won't fix. ------------------------------------------------------------------------ [2012-04-17 19:52:49] alec at smecher dot bc dot ca PostgreSQL is hard-coded to parse numeric values using "." as the decimal point (see https://github.com/postgres/postgres/blob/master/src/backend/utils/adt/numeric.c in set_var_from_str for implementation). This agrees with the SQL92 grammar for a numeric literal: http://savage.net.au/SQL/sql-92.bnf.html#exact%20numeric%20literal ...so by my reading PHP needs fixing. ------------------------------------------------------------------------ [2012-04-17 19:33:10] yohg...@php.net I've tried different locale see if it works and it doesn't. I also found this http://www.postgresql.org/docs/8.4/static/locale.html So , cannot replaced by . There is other case transparent usage is not allowed. Money is one of them. http://www.postgresql.org/docs/8.4/static/datatype-money.html If postgres is going to support conversion, then it is going to work, since it requires server side settings to work. (i.e. Database initialization, table definition) It is not a bug or feature that should be fixed in PHP. It's possible to do locale conversion in module, it would not be a good idea in general. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=46408 -- Edit this bug report at https://bugs.php.net/bug.php?id=46408&edit=1