Home » Database » DB_DataObject » Bug #3674
insert()/update() fails with boolean data type. Data coming from FormBuilder.
Details
| Submitted | 2005-03-02 18:55 UTC |
|---|---|
| From | carlosjordao at gmail dot com |
| Assigned | alan_k |
| Status | Closed |
| Package | DB_DataObject |
| PHP Version | 4.3.10 |
| OS | Linux Conectiva 9.0 |
| Roadmaps | (Not assigned) |
Comments
[2005-03-02 18:55 UTC] carlosjordao at gmail dot com
Description:
------------
This is similar to bug #228 reported before.
THE PROBLEM:
MySql accepts very well integer 0 and 1 as boolean values 'false' and 'true'. However, PostgreSQL (7.4.6) doesn't act in the same way. It expects explicts 'false' and 'true' strings, or '1' and '0', with quotes.
The problem now is that quoteSmart() of pgsql.php may not differ between integer and bool if data has no specific cast to bool. Even as the '18' DataType (STRING & BOOLEAN) field, the function quote() looks for data type through is_boolean(), is_integer(), making the '18' solution senseless (for PostgreSQL).
In this case, I use FormBuilder module to do the interface with DataObject, but due the debug() output [the problem is on update()/insert() queries], I suppose the code would fit better here.
Reproduce code:
---------------
THE SOLUTION:
I guess this would help. I have included those lines into my
DataObject.php
(before $v & DB_DATAOBJECT_STR in insert())
if ($v & DB_DATAOBJECT_BOOL) {
$rightq .= $DB->quote((bool)$this->$k) . " ";
continue;
}
(before $v & DB_DATAOBJECT_STR in update())
if ($v & DB_DATAOBJECT_BOOL) {
$settings .= "$kSql = ". $DB->quote((bool)$this->$k)
. ' ';
continue;
}
Expected result:
----------------
Supose table 'a':
CREATE TABLE a ( a bool );
EXPECTED OUPUT:
INSERT INTO a (a) VALUES ( TRUE );
(or at least INSERT INTO a (a) VALUES ( '1' ); )
Actual result:
--------------
INSERT INTO a (a) VALUES ( 1 );
[2005-03-02 19:07 UTC] pierre at dotgeek dot org
it's a DataObject bug.