Hi all,
I had the same problem with the following setup:
Ubuntu 12.04 + postgres 9.2 + PHP 5.4 + Yii 1.1.
I tried first the fix suggested from Zugluk:
adding in CdbCommandBuilder:208 (i.e. createInsertCommand function)
if($column->dbType==='boolean') //
$values[self::PARAM_PREFIX.$i]=$value;//
else//
$values[self::PARAM_PREFIX.$i]=$column->typecast($value);
It works when inserting a new entry in the table but
updates remained a problem.
I also tried to copy past the same code snippet in the
createUpdateCommand but with no results.
After some hours digging around Yii code I was able to
track back to another function: CDbColumnSchema::typecast($value)
CDbColumnSchema is a base class which is extended by database-dependent ones.
In the case of postresql the extended class is called CDbPgsqlColumnSchema.
I fixed the problem as follows:
Copied the function typecast($value) from the base class CDbColumnSchema.
Pasted it in the class CDbPgsqlColumnSchema.
Finally I added a control on the data type at the beginning of the freshly
copied function.
The final code (that is the one that you have to insert in the CDbPgsqlColumnSchema class)
is the following
/**
* Converts the input value to the type that this column is of.
* @param mixed $value input value
* @return mixed converted value
*/
public function typecast($value)
{
/*WARNING: I had to add this check:
* when the table column is a boolean there are problems because php
* represents boolean differently and there is a misconversion
* with this modification it seems to work
*/
if(stripos($this->type,'bool')!==false){
if($value===TRUE || $value===true || $value === 't' || $value === 'true' ||
$value==='y' || $value==='yes' || $value==='on' ||
$value==='1' || $value===1 )
return 'true';
else
return 'false';
}
//END OF MODIFICATION
if(gettype($value)===$this->type || $value===null || $value instanceof CDbExpression)
return $value;
if($value==='')
return $this->type==='string' ? '' : null;
switch($this->type)
{
case 'string': return (string)$value;
case 'integer': return (integer)$value;
case 'boolean': return (boolean)$value;
case 'double':
default: return $value;
}
}
With this code in place everything seems to work (inserts as well as updates).
You can remove the patch provided by Zugluck as well.
cheers