Bug #68156 [Com]: pg_query_params Sets Boolean False to Blank String

From: Date: Sun, 05 Oct 2014 09:30:01 +0000
Subject: Bug #68156 [Com]: pg_query_params Sets Boolean False to Blank String
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187856@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68156&edit=1

 ID:                 68156
 Comment by:         nexisentertainment at gmail dot com
 Reported by:        nexisentertainment at gmail dot com
 Summary:            pg_query_params Sets Boolean False to Blank String
 Status:             Open
 Type:               Bug
 Package:            PostgreSQL related
 Operating System:   Debian Linux (Jessie)
 PHP Version:        5.6.1
 Block user comment: N
 Private report:     N

 New Comment:

Created a simplified test phpt.  Used it to verify the issue still exists on git (commit
429e1b45a7cd2f491e836f4bffa57c72beb6128b).

https://gist.github.com/N3X15/56ab6238a5a8e57bdc32

Can link if someone hates gists.  Will now attempt to sleep.


Previous Comments:
------------------------------------------------------------------------
[2014-10-05 07:50:48] nexisentertainment at gmail dot com

Should be more clear.

------------------------------------------------------------------------
[2014-10-05 07:45:36] nexisentertainment at gmail dot com

Description:
------------
pg_query_params somehow converts (boolean)false (as a parameter) to a blank string before sending it
to postgres.

Note, behavior has not been documented, but has been mentioned by a user comment: http://php.net/manual/en/function.pg-query-params.php#115063

I therefore conclude I am not crazy and imagining things.

May be related to #19575.

Test script:
---------------
<?php
// NOTE:  General layout unabashedly stolen from [FILE] of https://github.com/php/php-src/blob/master/ext/pgsql/tests/bug64609.phpt
$conn_str='user=test password=test host=localhost dbname=test';
error_reporting(E_ALL);
$db = pg_connect($conn_str);
foreach(array(TRUE,FALSE) as $bool) {
    echo "Inserting ".($bool?'true':'false');
    pg_query("BEGIN");
    pg_query("CREATE TABLE test_bool_table (a boolean)");
    $values = array($bool);
    pg_query_params($db,'INSERT INTO test_bool_table (a) VALUES ($1)',$values);
    pg_query("ROLLBACK");
}

Expected result:
----------------
No errors, output of:

  Inserting true
  Inserting false

Actual result:
--------------
Inserting true
Inserting false
Warning: pg_query_params(): Query failed: ERROR: invalid input syntax for type boolean: ""
in /host/[NOPE]/htdocs/testpgbug.php on line 13


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=68156&edit=1


Thread (9 messages)

« previous php.bugs (#187856) next »