Bug #68783 [NEW]: pgsql: PDO::fetchColumn() false returned for value false and no rows returned

From: Date: Fri, 09 Jan 2015 21:01:37 +0000
Subject: Bug #68783 [NEW]: pgsql: PDO::fetchColumn() false returned for value false and no rows returned
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-189851@lists.php.net to get a copy of this message
From:             jon dot dufresne at gmail dot com
Operating system: Linux
PHP version:      5.5.20
Package:          PDO PgSQL
Bug Type:         Bug
Bug description:pgsql: PDO::fetchColumn() false returned for value false and no rows returned

Description:
------------
PostgreSQL has proper support for boolean fields. Boolean database
fields are returned to PHP as boolean values. Additionally, when using
fetchColumn() it is often useful to know if no rows were returned. PDO
reports this by returning the value false. There is a conflict here as
false is now overloaded to represent both "no rows returned" and "column
value false". These are two distinct cases that may need to be handled
separately.

$ php --version
PHP 5.5.20 (cli) (built: Dec 18 2014 05:55:32) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend
Technologies
    with Xdebug v2.2.6, Copyright (c) 2002-2014, by Derick Rethans

The following script demonstrates this behavior.

Test script:
---------------
<?php

$db = new PDO('pgsql:dbname=test', 'postgres');

$db->exec('DROP TABLE IF EXISTS test_table');
$db->exec('CREATE TABLE test_table (field boolean)');

$stmt = $db->query('SELECT * FROM test_table');
var_dump($stmt->fetchColumn());

$db->exec('INSERT INTO test_table VALUES (FALSE)');
$stmt = $db->query('SELECT * FROM test_table');
var_dump($stmt->fetchColumn());


Expected result:
----------------
I expect the two var_dumps() to return different values, but they do
not. (Alternatively, if an exception was thrown that would also work,
but PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION does not make this
happen.)

Actual result:
--------------
bool(false)
bool(false)


The two var_dump()s are identical making it difficult to know if no rows
were returned or the value false was returned.

-- 
Edit bug report at https://bugs.php.net/bug.php?id=68783&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=68783&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=68783&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=68783&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=68783&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=68783&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=68783&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=68783&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=68783&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=68783&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=68783&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=68783&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=68783&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=68783&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68783&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=68783&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=68783&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=68783&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68783&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=68783&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=68783&r=mysqlcfg



Thread (1 message)

  • jon dot dufresne at gmail dot com
« previous php.bugs (#189851) next »