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:
I believe pg_query_params is broken until this is resolved, but it looks like
we're not going to agree on it. I hope someone else can speak up if they do
think this is a bug.
Since we disagree on the approach any patch I write to correct it will be
rejected.
I'll add a comment to the manual page for pg_query_params to document this.
Previous Comments:
------------------------------------------------------------------------
[2012-04-18 02:26:48] [email protected]
BTW, you are reading PostgreSQL manual wrong.
libpq's functions never care about data types, but the server is.
If you are curious still, try to make patch that meets the requirement I've
wrote.
------------------------------------------------------------------------
[2012-04-18 02:19:38] [email protected]
IIRC, MDB2 cares data types. (which I think it's a design problem for loosely
type langs.) Therefore, it may change behavior according to locale.
Anyway, It's not a matter of argument. It's the way it works. As I explained
repeatedly, ALL params are passed as string and types are NEVER cared in C API.
To know the data type, module should issue an additional query to get meta
data.
Additional query for each query is severe performance hit.
Therefore, it is a PHP programmer's responsibility (or Perhaps, PostgreSQL. If
they would like to change behavior via client environment vars. I guess they
would not.)
If you could submit patch that works for all data types and does not require
additional query, I'll review it.
------------------------------------------------------------------------
[2012-04-18 01:30:38] alec at smecher dot bc dot ca
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.
------------------------------------------------------------------------
[2012-04-17 21:36:47] [email protected]
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).
------------------------------------------------------------------------
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