PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB_DataObject » Bug #4152

Boolean value to Tiny-int

Details

Submitted2005-04-15 12:33 UTC
Frominfo at smies dot com
StatusDuplicate
PackageDB_DataObject
PHP Version5.0.0
OSWIN2000
Roadmaps(Not assigned)

Comments

[2005-04-15 12:33 UTC] info at smies dot com

Description:
------------
Version: $Id: DataObject.php,v 1.341 2005/03/23 02:03:22 alan_k Exp $

In Mysql 4.1 I use a tinyint(1) as a boolean field (as Mysql has no real boolean field). When I set a boolean value and not a integer in a field that uses that tinyint then I expect that the query wil contain 0 or 1. This doesn't happen because the _build_condition method doesn't
recognise the boolean a numeric. It then supplies the representing ini number to the query (which I find a bit strang, by the way).

The following code is responsible (line 2251):
if (is_numeric($this->$k)){
$this->whereAdd(" $kSql = {$this->$k}");
continue;
}

If you replace the code with the following code then it is resolved:

if (is_numeric($this->$k) || is_bool($this->$k)) {
$this->whereAdd(" $kSql = " . (int) $this->$k);
continue;
}

Reproduce code:
---------------
This is a piece of code that uses a boolean value. The deleted field is a tinyint(1):

$image = new Image()
$image->deleted = false;
$numRecords = $image->count();

Expected result:
----------------
I am expecting the following query from the count method:

SELECT count(`image`.`id`) as `DATAOBJECT_NUM`
FROM `image` WHERE `image`.`deleted` = 0

Actual result:
--------------
I am getting the following query from the count method:

SELECT count(`image`.`id`) as `DATAOBJECT_NUM`
FROM `image` WHERE `image`.`deleted` = 145

The 145 is the code in the ini file that represents the tinyint value.