Hi all again (after a very long time). Just a couple of more little things.
So in the class CPgsqlColumnSchema add the code:
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 ||
stripos($this->type,'boolean')!==false){
if(is_string($value)) $lower_value = strtolower($value);
if($value===TRUE || $value===true || $lower_value === 't' || $lower_value === 'true' ||
$lower_value==='y' || $lower_value==='yes' || $lower_value==='on' ||
$lower_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===''){ //
if($this->type === 'bool') //KLUDGE If it's a boolean, when there is void we return '0'
return '0'; //
else //
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;
}
}
Note that there is a small modification with respect to the code posted by Zugluk. The change is:
if(is_string($value)) $lower_value = strtolower($value);
if($value===TRUE || $value===true || $lower_value === 't' || $lower_value === 'true' ||
$lower_value==='y' || $lower_value==='yes' || $lower_value==='on' ||
$lower_value==='1' || $value===1 )
return 'true';
else
return 'false';
This is necessary for including any possible typing (e.g. TRUE, true, True, FALSE, False , and so on).
Moreover, it is necessary to modify the function createColumnCriteria in the class CDBCommandBuilder (at least in the version of the file I have) as follows:
public function createColumnCriteria($table,$columns,$condition='',$params=array(),$prefix=null)
{
$this->ensureTable($table);
$criteria=$this->createCriteria($condition,$params);
if($criteria->alias!='')
$prefix=$this->_schema->quoteTableName($criteria->alias).'.';
$bindByPosition=isset($criteria->params[0]);
$conditions=array();
$values=array();
$i=0;
if($prefix===null)
$prefix=$table->rawName.'.';
foreach($columns as $name=>$value)
{
if(($column=$table->getColumn($name))!==null)
{
if(is_array($value))
$conditions[]=$this->createInCondition($table,$name,$value,$prefix);
else if($value!==null)
{
if($bindByPosition)
{
$conditions[]=$prefix.$column->rawName.'=?';
$values[]=$value;
}
else
{
$conditions[]=$prefix.$column->rawName.'='.self::PARAM_PREFIX.$i;
/* OLD
$values[self::PARAM_PREFIX.$i]=$column->typecast($value);
*/
$values[self::PARAM_PREFIX.$i]=$column->typecast($value);
$i++;
}
}
else
$conditions[]=$prefix.$column->rawName.' IS NULL';
}
else
throw new CDbException(Yii::t('yii','Table "{table}" does not have a column named "{column}".',
array('{table}'=>$table->name,'{column}'=>$name)));
}
$criteria->params=array_merge($values,$criteria->params);
if(isset($conditions[0]))
{
if($criteria->condition!='')
$criteria->condition=implode(' AND ',$conditions).' AND ('.$criteria->condition.')';
else
$criteria->condition=implode(' AND ',$conditions);
}
return $criteria;
}
The change is
/* OLD
$values[self::PARAM_PREFIX.$i]=$column->typecast($value);
*/
$values[self::PARAM_PREFIX.$i]=$column->typecast($value);
and it is necessary to make sure that active records use the typecast function defined above.
Cheers