]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Data/Common/TDbTableColumn.php
fe96e12afcfe1f5a326bb9b97af8470faf9d96d5
[bacula/bacula] / gui / baculum / framework / Data / Common / TDbTableColumn.php
1 <?php
2 /**
3  * TDbTableColumn class file.
4  *
5  * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
6  * @link http://www.pradosoft.com/
7  * @copyright Copyright &copy; 2005-2014 PradoSoft
8  * @license http://www.pradosoft.com/license/
9  * @package System.Data.Common
10  */
11
12 /**
13  * TDbTableColumn class describes the column meta data of the schema for a database table.
14  *
15  * @author Wei Zhuo <weizho[at]gmail[dot]com>
16  * @package System.Data.Common
17  * @since 3.1
18  */
19 class TDbTableColumn extends TComponent
20 {
21         const UNDEFINED_VALUE= INF; //use infinity for undefined value
22
23         private $_info=array();
24
25         /**
26          * Sets the table column meta data.
27          * @param array table column information.
28          */
29         public function __construct($columnInfo)
30         {
31                 $this->_info=$columnInfo;
32         }
33
34         /**
35          * @param string information array key name
36          * @param mixed default value if information array value is null
37          * @return mixed information array value.
38          */
39         protected function getInfo($name,$default=null)
40         {
41                 return isset($this->_info[$name]) ? $this->_info[$name] : $default;
42         }
43
44         /**
45          * @param string information array key name
46          * @param mixed new information array value.
47          */
48         protected function setInfo($name,$value)
49         {
50                 $this->_info[$name]=$value;
51         }
52
53         /**
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.
56          */
57         public function getPHPType()
58         {
59                 return 'string';
60         }
61
62         /**
63          * @param integer PDO bind param/value types, default returns string.
64          */
65         public function getPdoType()
66         {
67                 switch($this->getPHPType())
68                 {
69                         case 'boolean': return PDO::PARAM_BOOL;
70                         case 'integer': return PDO::PARAM_INT;
71                         case 'string' : return PDO::PARAM_STR;
72                 }
73                 return PDO::PARAM_STR;
74         }
75
76         /**
77          * @return string name of the column in the table (identifier quoted).
78          */
79         public function getColumnName()
80         {
81                 return $this->getInfo('ColumnName');
82         }
83
84         /**
85          * @return string name of the column with quoted identifier.
86          */
87         public function getColumnId()
88         {
89                 return $this->getInfo('ColumnId');
90         }
91
92         /**
93          * @return string size of the column.
94          */
95         public function getColumnSize()
96         {
97                 return $this->getInfo('ColumnSize');
98         }
99
100         /**
101          * @return integer zero-based ordinal position of the column in the table.
102          */
103         public function getColumnIndex()
104         {
105                 return $this->getInfo('ColumnIndex');
106         }
107
108         /**
109          * @return string column type.
110          */
111         public function getDbType()
112         {
113                 return $this->getInfo('DbType');
114         }
115
116         /**
117          * @return boolean specifies whether value Null is allowed, default is false.
118          */
119         public function getAllowNull()
120         {
121                 return $this->getInfo('AllowNull',false);
122         }
123
124         /**
125          * @return mixed default column value if column value was null.
126          */
127         public function getDefaultValue()
128         {
129                 return $this->getInfo('DefaultValue', self::UNDEFINED_VALUE);
130         }
131
132         /**
133          * @return string precision of the column data, if the data is numeric.
134          */
135         public function getNumericPrecision()
136         {
137                 return $this->getInfo('NumericPrecision');
138         }
139
140         /**
141          * @return string scale of the column data, if the data is numeric.
142          */
143         public function getNumericScale()
144         {
145                 return $this->getInfo('NumericScale');
146         }
147
148         public function getMaxiumNumericConstraint()
149         {
150                 if(($precision=$this->getNumericPrecision())!==null)
151                 {
152                         $scale=$this->getNumericScale();
153                         return $scale===null ? pow(10,$precision) : pow(10,$precision-$scale);
154                 }
155         }
156
157         /**
158          * @return boolean whether this column is a primary key for the table, default is false.
159          */
160         public function getIsPrimaryKey()
161         {
162                 return $this->getInfo('IsPrimaryKey',false);
163         }
164
165         /**
166          * @return boolean whether this column is a foreign key, default is false.
167          */
168         public function getIsForeignKey()
169         {
170                 return $this->getInfo('IsForeignKey',false);
171         }
172
173         /**
174          * @param string sequence name, only applicable if column is a sequence
175          */
176         public function getSequenceName()
177         {
178                 return $this->getInfo('SequenceName');
179         }
180
181         /**
182          * @return boolean whether the column is a sequence.
183          */
184         public function hasSequence()
185         {
186                 return $this->getSequenceName()!==null;
187         }
188
189         /**
190          * @return boolean whether this column is excluded from insert and update.
191          */
192         public function getIsExcluded()
193         {
194                 return false;
195         }
196 }
197