3 * TDbTableColumn class file.
5 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
6 * @link http://www.pradosoft.com/
7 * @copyright Copyright © 2005-2014 PradoSoft
8 * @license http://www.pradosoft.com/license/
9 * @package System.Data.Common
13 * TDbTableColumn class describes the column meta data of the schema for a database table.
15 * @author Wei Zhuo <weizho[at]gmail[dot]com>
16 * @package System.Data.Common
19 class TDbTableColumn extends TComponent
21 const UNDEFINED_VALUE= INF; //use infinity for undefined value
23 private $_info=array();
26 * Sets the table column meta data.
27 * @param array table column information.
29 public function __construct($columnInfo)
31 $this->_info=$columnInfo;
35 * @param string information array key name
36 * @param mixed default value if information array value is null
37 * @return mixed information array value.
39 protected function getInfo($name,$default=null)
41 return isset($this->_info[$name]) ? $this->_info[$name] : $default;
45 * @param string information array key name
46 * @param mixed new information array value.
48 protected function setInfo($name,$value)
50 $this->_info[$name]=$value;
54 * Returns the derived PHP primitive type from the db type. Default returns 'string'.
55 * @return string derived PHP primitive type from the column db type.
57 public function getPHPType()
63 * @param integer PDO bind param/value types, default returns string.
65 public function getPdoType()
67 switch($this->getPHPType())
69 case 'boolean': return PDO::PARAM_BOOL;
70 case 'integer': return PDO::PARAM_INT;
71 case 'string' : return PDO::PARAM_STR;
73 return PDO::PARAM_STR;
77 * @return string name of the column in the table (identifier quoted).
79 public function getColumnName()
81 return $this->getInfo('ColumnName');
85 * @return string name of the column with quoted identifier.
87 public function getColumnId()
89 return $this->getInfo('ColumnId');
93 * @return string size of the column.
95 public function getColumnSize()
97 return $this->getInfo('ColumnSize');
101 * @return integer zero-based ordinal position of the column in the table.
103 public function getColumnIndex()
105 return $this->getInfo('ColumnIndex');
109 * @return string column type.
111 public function getDbType()
113 return $this->getInfo('DbType');
117 * @return boolean specifies whether value Null is allowed, default is false.
119 public function getAllowNull()
121 return $this->getInfo('AllowNull',false);
125 * @return mixed default column value if column value was null.
127 public function getDefaultValue()
129 return $this->getInfo('DefaultValue', self::UNDEFINED_VALUE);
133 * @return string precision of the column data, if the data is numeric.
135 public function getNumericPrecision()
137 return $this->getInfo('NumericPrecision');
141 * @return string scale of the column data, if the data is numeric.
143 public function getNumericScale()
145 return $this->getInfo('NumericScale');
148 public function getMaxiumNumericConstraint()
150 if(($precision=$this->getNumericPrecision())!==null)
152 $scale=$this->getNumericScale();
153 return $scale===null ? pow(10,$precision) : pow(10,$precision-$scale);
158 * @return boolean whether this column is a primary key for the table, default is false.
160 public function getIsPrimaryKey()
162 return $this->getInfo('IsPrimaryKey',false);
166 * @return boolean whether this column is a foreign key, default is false.
168 public function getIsForeignKey()
170 return $this->getInfo('IsForeignKey',false);
174 * @param string sequence name, only applicable if column is a sequence
176 public function getSequenceName()
178 return $this->getInfo('SequenceName');
182 * @return boolean whether the column is a sequence.
184 public function hasSequence()
186 return $this->getSequenceName()!==null;
190 * @return boolean whether this column is excluded from insert and update.
192 public function getIsExcluded()