typeCast function in CDbColumnSchema doesn't cast double values

I don’t know why this is, but typeCast function doesn’t handle double values (do not cast them to “double” and return as they were passed to function as default action):




public function typecast($value)

	{

		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;

		}

	}



it should be:




public function typecast($value)

	{

		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': return (double)$value;

			default: return $value;

		}

	}



without this there is a problem with oracle connection when calling findByPk - createPkCriteria function call quote for PK value, which has string type beceuse of the above bug, and pdo::quote return empty string for it… which is also strange but it works so under linux. under windows I haven’t notice such problems on very same Yii application.

with patch like above everything works fine.

Hmm… it really looks like bug i PDO_OCI under linux, to reproduce try:




$v = '23';

$v2 = Yii::app()->db->quoteValue( $v );

echo "v=$v, v2=$v2";



it shows:


v=23, v2=

ok… it WAS old PDO_OCI (1.0) module. I didn’t implement “quote” function at all.

anyway - I think that typeCast function should be changed, but now it is not so urgent for me :)

Hi,

I also experience problem with typecast() method when using MSSQL.

When I create MSSQL table with default definitions like this:




CREATE TABLE category (

  id int IDENTITY (1,1) NOT NULL,

  name varchar(255) NULL Default (NULL),

  description text,

  deleted varchar(1) DEFAULT '0',

  created_date int Default (NULL),

  created_user_id NULL Default (NULL),

  modified_date int Default (NULL),

  modified_user_id int Default (NULL),

  PRIMARY KEY (id),

) ;



then atttribute Category::model()->name will be pre-filled with default value string "NULL". This causes that all textfields in view will be prefilled with "NULL" string. MySQL will be set correctly to default value undefined NULL.

A workaround for this is change table creation without default definitions:




CREATE TABLE category (

  id int IDENTITY (1,1) NOT NULL,

  name varchar(255) NULL,

  description text,

  deleted varchar(1) DEFAULT '0',

  created_date int NULL,

  created_user_id int NULL,

  modified_date int NULL,

  modified_user_id int NULL,

  PRIMARY KEY (id),

) ;



Cheers

lubosdz