The following bug has been logged online:

Bug reference: 5054
Logged by: Yujin
Email address: aloudnoise@mail.ru
PostgreSQL version: 8.3
Operating system: windows XP SP3
Description: PDO -> Query returns "" from Boolean type field, if it
has false value.
Details:

When i get query from table with bolean type fields, that have false value ,
function PDO -> fetch return that fields with not "0" value , but empty
string.

Search Discussions

  • Tom Lane at Sep 14, 2009 at 2:28 pm

    "Yujin" <aloudnoise@mail.ru> writes:
    When i get query from table with bolean type fields, that have false value ,
    function PDO -> fetch return that fields with not "0" value , but empty
    string.
    Are you sure the field is actually false, and not null?

    If so, this is a PDO bug, not a Postgres bug.

    regards, tom lane
  • Mark Kirkwood at Sep 15, 2009 at 6:22 am

    Tom Lane wrote:
    "Yujin" <aloudnoise@mail.ru> writes:
    When i get query from table with bolean type fields, that have false value ,
    function PDO -> fetch return that fields with not "0" value , but empty
    string.
    Are you sure the field is actually false, and not null?

    If so, this is a PDO bug, not a Postgres bug.

    regards, tom lane
    Does seem to be a PDO bug or some sort:

    Trying out some code with Php 5.3.1-dev:

    $sql = "SELECT false";
    $stmt = $dbh->query($sql);
    $result = $stmt->fetch(PDO::FETCH_NUM);
    print(" " . $result[0] . "\n");

    reproduces what Yujin is seeing, whereas replacing $sql with:

    $sql = "SELECT false::int4";

    gives a 0 in the result array. I guess it must be something funny with
    how PDO represents the bool type...(will have a look at the PDI code).
    But this needs to be raised on bugs.php.net.

    Cheers

    Mark
  • Mark Kirkwood at Sep 15, 2009 at 6:28 am

    Mark Kirkwood wrote:
    I guess it must be something funny with how PDO represents the bool
    type...(will have a look at the PDO code). But this needs to be raised
    on bugs.php.net.

    FYI - a related bug is : http://bugs.php.net/bug.php?id=33876
  • Mark Kirkwood at Sep 15, 2009 at 11:29 pm

    I wrote:

    Trying out some code with Php 5.3.1-dev:

    $sql = "SELECT false";
    $stmt = $dbh->query($sql);
    $result = $stmt->fetch(PDO::FETCH_NUM);
    print(" " . $result[0] . "\n");

    reproduces what Yujin is seeing...
    After a bit of digging through the PDO code, I see what is happening.
    the ->fetch operation is returning a Php boolean correctly from PDO (you
    can use var_dump($result[0]) to check this), but when you use print as
    above, Php casts the boolean to string - and for whatever reason Php
    reckons turning (boolean)false into (string)"" is the way to go. So to
    get a sensible result you need to do something like:

    $result = $stmt->fetch(PDO::FETCH_NUM);
    print(" " . (integer) $result[0] . "\n");

    i.e: explicit cast on the result value.

    This is confusing and seemingly not consistent - for instance the Mysql
    version of this example returns a string "0" from PDO, so gives a 0 for
    false in a more expected/intuitive way...

    regards

    Mark

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppgsql-bugs @
categoriespostgresql
postedSep 14, '09 at 10:00a
activeSep 15, '09 at 11:29p
posts5
users3
websitepostgresql.org
irc#postgresql

3 users in discussion

Mark Kirkwood: 3 posts Yujin: 1 post Tom Lane: 1 post

People

Translate

site design / logo © 2021 Grokbase