Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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