[Solved] Postgresql numeric datatype bug

‘Numeric’ data type is not considered a double and when read from a form if the form field is not filled it is set to empty string ‘’ instead of NULL. But this is not correct and when trying to save the model in the database there is a database error.

I think the error is in CPgsqlColumnSchema, function extractType. See framework snippet below:


	protected function extractType($dbType)

	{

		if(strpos($dbType,'char')!==false || strpos($dbType,'text')!==false)

			$this->type='string';

		else if(strpos($dbType,'bool')!==false)

			$this->type='boolean';

		else if(preg_match('/(real|float|double)/',$dbType))

			$this->type='double';

		else if(preg_match('/(integer|oid|serial|smallint)/',$dbType))

			$this->type='integer';

		else

			$this->type='string';

	}



The line that checks if a datatype is a double only checks for ‘real|float|double’ and I wonder why ‘numeric’ is left out of this list? As you see if a datatype is not found the default behavior is to treat it as a string.

If you add ‘numeric’ to that list it works properly, at least in my application. Yii mantainers please have a look.

Thanks!

-soso

Check this thread… http://www.yiiframework.com/forum/index.php?/topic/7683-cdbexception-on-inserting-empty-value-for-numeric-fields/page__hl__numeric__fromsearch__1

Answer from Qiang:

mdomba thank you very much for the prompt reply! I had a hunch that this is not really a bug and now it is all clear.