Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.5.0b5

Bug #8668 Inconsistent return values for boolean types
Submitted: 2006-09-08 21:45 UTC
From: jose at infoviaweb dot com Assigned:
Status: Bogus Package: MDB2 (version 2.2.2)
PHP Version: Irrelevant OS: irrelevant
Roadmaps: (Not assigned)    
Subscription  
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes. If this is not your bug, you can add a comment by following this link. If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
2006-09-09 17:23 UTC
Package:
Bug Type:
Summary:
From: jose at infoviaweb dot com
New email:
PHP Version: Package Version: OS:

 

 [2006-09-08 21:45 UTC] jose at infoviaweb dot com (José de Paula Rodrigues)
Description: ------------ I'm using both MDB2_Driver_mysql and MDB2_Driver_pgsql. When I query for a boolean field, the MDB2_Driver_pgsql returns 't' or 'f', but the MDB2_Driver_mysql returns 1 or 0. I haven't tested other drivers, but I suspect they show this same inconsistency. They should return either true, false or null, or 't', 'f', or 'null'; anything, as long as all drivers are consistent. Versions used: PHP 5.1.5 (from FreeBSD ports) MySQL 5.1.11 (beta) (from FreeBSD ports) PostgreSQL 8.1.4 (from FreeBSD ports) MDB2 2.2.2 (from channel PEAR.PHP.NET) MDB2_Driver_mysql 1.2.2 (from channel PEAR.PHP.NET) MDB2_Driver_pgsql 1.2.2 (from channel PEAR.PHP.NE) Test script: --------------- <?php require_once "MDB2.php"; $dsn = "mysql://someuser:somepassword@somehost/somedb"; //$dsn = "pgsql://someuser:somepassword@somehost/somedb"; /* the table tbl below is defined as: CREATE TABLE tbl ( value1 bool, value2 bool ); INSERT INTO tbl (value1, value2) VALUES(true, false); */ $db =& MDB2::connect($dsn); $sql = "SELECT * FROM tbl"; $rs = $db->query($sql); // error check ommited while($row = $rs->fetchRow()) { echo "value1: " . $row[0]; // pgsql shows 't', mysql shows '1' echo "\nvalue2: " . $row[1]; // pgsql shows 'f', mysql shows '0' } ?> Expected result: ---------------- value 1: true value 2: false or value 1: t value 2: f consistently across all databases Actual result: -------------- mysql returns value 1: 1 value 2: 0 pgsql returns value 1: t value 2: f

Comments

 [2006-09-09 17:23 UTC] lsmith (Lukas Smith)
You need to inform MDB2 of the types of your result columns if you want to get datatype abstraction for selects: $db->query($sql, array('boolean', 'boolean'));
 [2011-01-21 20:59 UTC] sjamaan (Peter Bex)
I think this bug is still relevant. The behaviour is inconsistent because with MySQL, when using the createTable function from the manager with a boolean type, the return value from fetchRow on that table is not a boolean. With other database engines like PostgreSQL this is the case. Since the createTable maps booleans to tinyint(1), I'd expect all tinyint(1) columns to be mapped back to booleans too. test script: -------------- $conn->loadModule('Manager'); $conn->manager->createTable('foo', array('x' => array('type' => 'boolean'))); $conn->loadModule('Extended'); $conn->extended->autoExecute('foo', array('x' => true), MDB2_AUTOQUERY_INSERT); $res = $conn->query('SELECT x FROM foo', true); var_dump($res->fetchRow(MDB2_FETCHMODE_ASSOC)); expected result: array(1) { ["x"] => bool(true) } actual result: array(1) { ["x"] => int(1) } The proposed patch fixes this without requiring the user to interfere. It should not break anything except rare cases where people are actually asking for an integer field with length 1.
 [2011-01-21 20:59 UTC] sjamaan (Peter Bex)