3 * TDbTableColumn class file.
5 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
6 * @link http://www.pradosoft.com/
7 * @copyright Copyright © 2005-2013 PradoSoft
8 * @license http://www.pradosoft.com/license/
9 * @version $Id: TDbTableColumn.php 3245 2013-01-07 20:23:32Z ctrlaltca $
10 * @package System.Data.Common
14 * TDbTableColumn class describes the column meta data of the schema for a database table.
16 * @author Wei Zhuo <weizho[at]gmail[dot]com>
17 * @version $Id: TDbTableColumn.php 3245 2013-01-07 20:23:32Z ctrlaltca $
18 * @package System.Data.Common
21 class TDbTableColumn extends TComponent
23 const UNDEFINED_VALUE= INF; //use infinity for undefined value
25 private $_info=array();
28 * Sets the table column meta data.
29 * @param array table column information.
31 public function __construct($columnInfo)
33 $this->_info=$columnInfo;
37 * @param string information array key name
38 * @param mixed default value if information array value is null
39 * @return mixed information array value.
41 protected function getInfo($name,$default=null)
43 return isset($this->_info[$name]) ? $this->_info[$name] : $default;
47 * @param string information array key name
48 * @param mixed new information array value.
50 protected function setInfo($name,$value)
52 $this->_info[$name]=$value;
56 * Returns the derived PHP primitive type from the db type. Default returns 'string'.
57 * @return string derived PHP primitive type from the column db type.
59 public function getPHPType()
65 * @param integer PDO bind param/value types, default returns string.
67 public function getPdoType()
69 switch($this->getPHPType())
71 case 'boolean': return PDO::PARAM_BOOL;
72 case 'integer': return PDO::PARAM_INT;
73 case 'string' : return PDO::PARAM_STR;
75 return PDO::PARAM_STR;
79 * @return string name of the column in the table (identifier quoted).
81 public function getColumnName()
83 return $this->getInfo('ColumnName');
87 * @return string name of the column with quoted identifier.
89 public function getColumnId()
91 return $this->getInfo('ColumnId');
95 * @return string size of the column.
97 public function getColumnSize()
99 return $this->getInfo('ColumnSize');
103 * @return integer zero-based ordinal position of the column in the table.
105 public function getColumnIndex()
107 return $this->getInfo('ColumnIndex');
111 * @return string column type.
113 public function getDbType()
115 return $this->getInfo('DbType');
119 * @return boolean specifies whether value Null is allowed, default is false.
121 public function getAllowNull()
123 return $this->getInfo('AllowNull',false);
127 * @return mixed default column value if column value was null.
129 public function getDefaultValue()
131 return $this->getInfo('DefaultValue', self::UNDEFINED_VALUE);
135 * @return string precision of the column data, if the data is numeric.
137 public function getNumericPrecision()
139 return $this->getInfo('NumericPrecision');
143 * @return string scale of the column data, if the data is numeric.
145 public function getNumericScale()
147 return $this->getInfo('NumericScale');
150 public function getMaxiumNumericConstraint()
152 if(($precision=$this->getNumericPrecision())!==null)
154 $scale=$this->getNumericScale();
155 return $scale===null ? pow(10,$precision) : pow(10,$precision-$scale);
160 * @return boolean whether this column is a primary key for the table, default is false.
162 public function getIsPrimaryKey()
164 return $this->getInfo('IsPrimaryKey',false);
168 * @return boolean whether this column is a foreign key, default is false.
170 public function getIsForeignKey()
172 return $this->getInfo('IsForeignKey',false);
176 * @param string sequence name, only applicable if column is a sequence
178 public function getSequenceName()
180 return $this->getInfo('SequenceName');
184 * @return boolean whether the column is a sequence.
186 public function hasSequence()
188 return $this->getSequenceName()!==null;
192 * @return boolean whether this column is excluded from insert and update.
194 public function getIsExcluded()