summaryrefslogtreecommitdiff
path: root/framework/Db/schema/TDbColumnSchema.php
diff options
context:
space:
mode:
authorrojaro <>2009-07-13 13:56:07 +0000
committerrojaro <>2009-07-13 13:56:07 +0000
commitb4b2c7e5e2eadd48b344538823dcf5645939ba44 (patch)
tree7e10a68d038fe37d71f7f7a8552136cecfb38183 /framework/Db/schema/TDbColumnSchema.php
parentd6ef8e39d858de50107950180ea111349e4b0d6f (diff)
- removed old schema directory
- some cleanups
Diffstat (limited to 'framework/Db/schema/TDbColumnSchema.php')
-rwxr-xr-xframework/Db/schema/TDbColumnSchema.php145
1 files changed, 0 insertions, 145 deletions
diff --git a/framework/Db/schema/TDbColumnSchema.php b/framework/Db/schema/TDbColumnSchema.php
deleted file mode 100755
index 094ef8e0..00000000
--- a/framework/Db/schema/TDbColumnSchema.php
+++ /dev/null
@@ -1,145 +0,0 @@
-<?php
-/**
- * TDbColumnSchema class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.yiiframework.com/
- * @copyright Copyright &copy; 2008-2009 Yii Software LLC
- * @license http://www.yiiframework.com/license/
- */
-
-prado::using('System.db.schema.TDbExpression');
-
-/**
- * TDbColumnSchema class describes the column meta data of a database table.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package system.db.schema
- * @since 1.0
- */
-class TDbColumnSchema extends TComponent
-{
- /**
- * @var string name of this column (without quotes).
- */
- public $name;
- /**
- * @var string raw name of this column. This is the quoted name that can be used in SQL queries.
- */
- public $rawName;
- /**
- * @var boolean whether this column can be null.
- */
- public $allowNull;
- /**
- * @var string the DB type of this column.
- */
- public $dbType;
- /**
- * @var string the PHP type of this column.
- */
- public $type;
- /**
- * @var mixed default value of this column
- */
- public $defaultValue;
- /**
- * @var integer size of the column.
- */
- public $size;
- /**
- * @var integer precision of the column data, if it is numeric.
- */
- public $precision;
- /**
- * @var integer scale of the column data, if it is numeric.
- */
- public $scale;
- /**
- * @var boolean whether this column is a primary key
- */
- public $isPrimaryKey;
- /**
- * @var boolean whether this column is a foreign key
- */
- public $isForeignKey;
-
-
- /**
- * Initializes the column with its DB type and default value.
- * This sets up the column's PHP type, size, precision, scale as well as default value.
- * @param string the column's DB type
- * @param mixed the default value
- */
- public function init($dbType, $defaultValue)
- {
- $this->dbType=$dbType;
- $this->extractType($dbType);
- $this->extractLimit($dbType);
- if($defaultValue!==null)
- $this->extractDefault($defaultValue);
- }
-
- /**
- * Extracts the PHP type from DB type.
- * @param string DB type
- */
- protected function extractType($dbType)
- {
- if(stripos($dbType,'int')!==false)
- $this->type='integer';
- else if(stripos($dbType,'bool')!==false)
- $this->type='boolean';
- else if(preg_match('/(real|floa|doub)/i',$dbType))
- $this->type='double';
- else
- $this->type='string';
- }
-
- /**
- * Extracts size, precision and scale information from column's DB type.
- * @param string 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 the default value obtained from metadata
- */
- protected function extractDefault($defaultValue)
- {
- $this->defaultValue=$this->typecast($defaultValue);
- }
-
- /**
- * Converts the input value to the type that this column is of.
- * @param mixed input value
- * @return mixed converted value
- */
- public function typecast($value)
- {
- if(gettype($value)===$this->type || $value===null || $value instanceof TDbExpression)
- return $value;
- if($value==='')
- return $this->type==='string' ? '' : null;
- switch($this->type)
- {
- case 'integer': return (integer)$value;
- case 'boolean': return (boolean)$value;
- case 'double': return (double)$value;
- case 'string': return (string)$value;
- default: return $value;
- }
- }
-}