From b00a84762c3771bd5c1bf51c01c3920f7e4a1633 Mon Sep 17 00:00:00 2001 From: p0larbeer Date: Mon, 2 Dec 2013 23:30:51 -0800 Subject: [PATCH] Create ColumnSchema.php --- framework/yii/db/oci/ColumnSchema.php | 88 +++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 framework/yii/db/oci/ColumnSchema.php diff --git a/framework/yii/db/oci/ColumnSchema.php b/framework/yii/db/oci/ColumnSchema.php new file mode 100644 index 0000000..90c80fd --- /dev/null +++ b/framework/yii/db/oci/ColumnSchema.php @@ -0,0 +1,88 @@ +dbType=$dbType; + $this->extractType($dbType); + $this->extractLimit($dbType); + if($defaultValue!==null) + $this->extractDefault($defaultValue); + } + + /** + * Extracts the PHP type from DB type. + * @param string $dbType DB type + * @return string + */ + protected function extractOraType($dbType){ + if(strpos($dbType,'FLOAT')!==false) return 'double'; + + if (strpos($dbType,'NUMBER')!==false || strpos($dbType,'INTEGER')!==false) + { + if(strpos($dbType,'(') && preg_match('/\((.*)\)/',$dbType,$matches)) + { + $values=explode(',',$matches[1]); + if(isset($values[1]) and (((int)$values[1]) > 0)) + return 'double'; + else + return 'integer'; + } + else + return 'double'; + } + else + return 'string'; + } + + /** + * Extracts the PHP type from DB type. + * @param string $dbType DB type + */ + protected function extractType($dbType) + { + $this->type=$this->extractOraType($dbType); + } + + /** + * Extracts size, precision and scale information from column's DB type. + * @param string $dbType the column's DB type + */ + protected function extractLimit($dbType) + { + if(strpos($dbType,'(') && preg_match('/\((.*)\)/',$dbType,$matches)) + { + $values=explode(',',$matches[1]); + $this->size=$this->precision=(int)$values[0]; + if(isset($values[1])) + $this->scale=(int)$values[1]; + } + } + + /** + * Extracts the default value for the column. + * The value is typecasted to correct PHP type. + * @param mixed $defaultValue the default value obtained from metadata + */ + protected function extractDefault($defaultValue) + { + if(stripos($defaultValue,'timestamp')!==false) { + $this->defaultValue=null; + } + else { + $this->defaultValue=$this->typecast($defaultValue); + } + } + +}